1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-06 08:10:25 +08:00

fix: empty para in tablecell

This commit is contained in:
源文雨
2023-03-06 14:08:40 +08:00
parent bce9c3b8dc
commit e3d6e419d5
8 changed files with 178 additions and 169 deletions

View File

@@ -38,6 +38,8 @@ func newEmptyA4File() *Docx {
XMLWPC: XMLNS_WPC,
XMLWPG: XMLNS_WPG,
// XMLMC: XMLNS_MC,
// XMLO: XMLNS_O,
// XMLV: XMLNS_V,
// XMLWP14: XMLNS_WP14,
Body: Body{
Items: make([]interface{}, 0, 64),

View File

@@ -34,9 +34,12 @@ const (
XMLNS_WPS = `http://schemas.microsoft.com/office/word/2010/wordprocessingShape`
XMLNS_WPC = `http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas`
XMLNS_WPG = `http://schemas.microsoft.com/office/word/2010/wordprocessingGroup`
// XMLNS_MC = `http://schemas.openxmlformats.org/markup-compatibility/2006`
XMLNS_MC = `http://schemas.openxmlformats.org/markup-compatibility/2006`
// XMLNS_WP14 = `http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing`
XMLNS_O = `urn:schemas-microsoft-com:office:office`
XMLNS_V = `urn:schemas-microsoft-com:vml`
XMLNS_PICTURE = `http://schemas.openxmlformats.org/drawingml/2006/picture`
)
@@ -108,6 +111,11 @@ type Document struct {
// XMLMC string `xml:"xmlns:mc,attr,omitempty"` // cannot be unmarshalled in
// XMLWP14 string `xml:"xmlns:wp14,attr,omitempty"` // cannot be unmarshalled in
// XMLO string `xml:"xmlns:o,attr,omitempty"` // cannot be unmarshalled in
// XMLV string `xml:"xmlns:v,attr,omitempty"` // cannot be unmarshalled in
// MCIgnorable string `xml:"mc:Ignorable,attr,omitempty"`
Body Body `xml:"w:body"`
}

View File

@@ -111,6 +111,19 @@ func (r *Run) parse(d *xml.Decoder, tt xml.StartElement) (child interface{}, err
case "tab":
child = &Tab{}
case "AlternateContent":
/*var value AlternateContent
value.file = r.file
err = d.DecodeElement(&value, &tt)
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return nil, err
}
if value.Choice == nil {
return nil, nil
}
if value.Choice.Requires != "wps" && value.Choice.Requires != "wpc" && value.Choice.Requires != "wpg" {
return nil, nil
}
child = &value*/
altcont:
for {
tok, err1 := d.Token()

View File

@@ -604,10 +604,8 @@ func (c *WTextBoxContent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
if len(value.Children) > 0 {
value.file = c.file
c.Paragraphs = append(c.Paragraphs, value)
}
value.file = c.file
c.Paragraphs = append(c.Paragraphs, value)
default:
err = d.Skip() // skip unsupported tags
if err != nil {

View File

@@ -560,10 +560,8 @@ func (c *WTableCell) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
return err
}
if len(value.Children) > 0 {
value.file = c.file
c.Paragraphs = append(c.Paragraphs, value)
}
value.file = c.file
c.Paragraphs = append(c.Paragraphs, value)
case "tcPr":
var value WTableCellProperties
err = d.DecodeElement(&value, &tt)
@@ -776,8 +774,8 @@ func (w *WTableBorders) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
// WTableBorder is a structure representing a single border of a Word table.
type WTableBorder struct {
Val string `xml:"w:val,attr"`
Size int `xml:"w:sz,attr,omitempty"`
Space int `xml:"w:space,attr,omitempty"`
Size int `xml:"w:sz,attr"`
Space int `xml:"w:space,attr"`
Color string `xml:"w:color,attr,omitempty"`
}

View File

@@ -83,6 +83,8 @@ func (f *Docx) parseDocument(file *zip.File) error {
f.Document.XMLR = XMLNS_R
f.Document.XMLWP = XMLNS_WP
// f.Document.XMLMC = XMLNS_MC
// f.Document.XMLO = XMLNS_O
// f.Document.XMLV = XMLNS_V
f.Document.XMLWPS = XMLNS_WPS
f.Document.XMLWPC = XMLNS_WPC
f.Document.XMLWPG = XMLNS_WPG

View File

@@ -7,16 +7,15 @@
xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex"
xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"
xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml"
xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash"
xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh">
xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex">
<w:docDefaults>
<w:rPrDefault>
<w:rPr>
<w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorEastAsia" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi"/>
<w:kern w:val="2"/>
<w:sz w:val="24"/>
<w:sz w:val="21"/>
<w:szCs w:val="24"/>
<w:lang w:val="en-US" w:eastAsia="zh-TW" w:bidi="ar-SA"/>
<w:lang w:val="en-US" w:eastAsia="zh-CN" w:bidi="ar-SA"/>
</w:rPr>
</w:rPrDefault>
<w:pPrDefault/>
@@ -116,7 +115,7 @@
<w:lsdException w:name="E-mail Signature" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="HTML Top of Form" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="HTML Bottom of Form" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="Normal (Web)" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="Normal (Web)" w:semiHidden="1" w:uiPriority="0" w:unhideWhenUsed="1"/>
<w:lsdException w:name="HTML Acronym" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="HTML Address" w:semiHidden="1" w:unhideWhenUsed="1"/>
<w:lsdException w:name="HTML Cite" w:semiHidden="1" w:unhideWhenUsed="1"/>
@@ -402,12 +401,13 @@
<w:style w:type="paragraph" w:default="1" w:styleId="a">
<w:name w:val="Normal"/>
<w:qFormat/>
<w:rsid w:val="00A955DD"/>
<w:rsid w:val="006F4226"/>
<w:pPr>
<w:widowControl w:val="0"/>
<w:jc w:val="both"/>
</w:pPr>
<w:rPr>
<w:szCs w:val="22"/>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="宋体" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
</w:rPr>
</w:style>
<w:style w:type="character" w:default="1" w:styleId="a0">
@@ -437,15 +437,28 @@
<w:semiHidden/>
<w:unhideWhenUsed/>
</w:style>
<w:style w:type="character" w:styleId="a3">
<w:name w:val="Hyperlink"/>
<w:basedOn w:val="a0"/>
<w:uiPriority w:val="99"/>
<w:unhideWhenUsed/>
<w:rsid w:val="003B745A"/>
<w:style w:type="table" w:styleId="a3">
<w:name w:val="Table Grid"/>
<w:basedOn w:val="a1"/>
<w:uiPriority w:val="39"/>
<w:rsid w:val="008E76B5"/>
<w:tblPr>
<w:tblBorders>
<w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
</w:tblBorders>
</w:tblPr>
</w:style>
<w:style w:type="paragraph" w:styleId="a4">
<w:name w:val="Normal (Web)"/>
<w:basedOn w:val="a"/>
<w:rsid w:val="006F4226"/>
<w:rPr>
<w:color w:val="0000FF" w:themeColor="hyperlink"/>
<w:u w:val="single"/>
<w:sz w:val="24"/>
</w:rPr>
</w:style>
</w:styles>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office-Design">
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office 主题​​">
<a:themeElements>
<a:clrScheme name="Office">
<a:dk1>
@@ -9,48 +9,48 @@
<a:sysClr val="window" lastClr="FFFFFF"/>
</a:lt1>
<a:dk2>
<a:srgbClr val="1F497D"/>
<a:srgbClr val="44546A"/>
</a:dk2>
<a:lt2>
<a:srgbClr val="EEECE1"/>
<a:srgbClr val="E7E6E6"/>
</a:lt2>
<a:accent1>
<a:srgbClr val="4F81BD"/>
<a:srgbClr val="4472C4"/>
</a:accent1>
<a:accent2>
<a:srgbClr val="C0504D"/>
<a:srgbClr val="ED7D31"/>
</a:accent2>
<a:accent3>
<a:srgbClr val="9BBB59"/>
<a:srgbClr val="A5A5A5"/>
</a:accent3>
<a:accent4>
<a:srgbClr val="8064A2"/>
<a:srgbClr val="FFC000"/>
</a:accent4>
<a:accent5>
<a:srgbClr val="4BACC6"/>
<a:srgbClr val="5B9BD5"/>
</a:accent5>
<a:accent6>
<a:srgbClr val="F79646"/>
<a:srgbClr val="70AD47"/>
</a:accent6>
<a:hlink>
<a:srgbClr val="0000FF"/>
<a:srgbClr val="0563C1"/>
</a:hlink>
<a:folHlink>
<a:srgbClr val="800080"/>
<a:srgbClr val="954F72"/>
</a:folHlink>
</a:clrScheme>
<a:fontScheme name="Office">
<a:majorFont>
<a:latin typeface="Cambria"/>
<a:latin typeface="等线 Light" panose="020F0302020204030204"/>
<a:ea typeface=""/>
<a:cs typeface=""/>
<a:font script="Jpan" typeface=" Pゴシック"/>
<a:font script="Jpan" typeface="游ゴシック Light"/>
<a:font script="Hang" typeface="맑은 고딕"/>
<a:font script="Hans" typeface="宋体"/>
<a:font script="Hans" typeface="等线 Light"/>
<a:font script="Hant" typeface="新細明體"/>
<a:font script="Arab" typeface="Times New Roman"/>
<a:font script="Hebr" typeface="Times New Roman"/>
<a:font script="Thai" typeface="Tahoma"/>
<a:font script="Thai" typeface="Angsana New"/>
<a:font script="Ethi" typeface="Nyala"/>
<a:font script="Beng" typeface="Vrinda"/>
<a:font script="Gujr" typeface="Shruti"/>
@@ -74,18 +74,35 @@
<a:font script="Viet" typeface="Times New Roman"/>
<a:font script="Uigh" typeface="Microsoft Uighur"/>
<a:font script="Geor" typeface="Sylfaen"/>
<a:font script="Armn" typeface="Arial"/>
<a:font script="Bugi" typeface="Leelawadee UI"/>
<a:font script="Bopo" typeface="Microsoft JhengHei"/>
<a:font script="Java" typeface="Javanese Text"/>
<a:font script="Lisu" typeface="Segoe UI"/>
<a:font script="Mymr" typeface="Myanmar Text"/>
<a:font script="Nkoo" typeface="Ebrima"/>
<a:font script="Olck" typeface="Nirmala UI"/>
<a:font script="Osma" typeface="Ebrima"/>
<a:font script="Phag" typeface="Phagspa"/>
<a:font script="Syrn" typeface="Estrangelo Edessa"/>
<a:font script="Syrj" typeface="Estrangelo Edessa"/>
<a:font script="Syre" typeface="Estrangelo Edessa"/>
<a:font script="Sora" typeface="Nirmala UI"/>
<a:font script="Tale" typeface="Microsoft Tai Le"/>
<a:font script="Talu" typeface="Microsoft New Tai Lue"/>
<a:font script="Tfng" typeface="Ebrima"/>
</a:majorFont>
<a:minorFont>
<a:latin typeface="Arial"/>
<a:latin typeface="等线" panose="020F0502020204030204"/>
<a:ea typeface=""/>
<a:cs typeface=""/>
<a:font script="Jpan" typeface=" Pゴシック"/>
<a:font script="Jpan" typeface="游明朝"/>
<a:font script="Hang" typeface="맑은 고딕"/>
<a:font script="Hans" typeface="宋体"/>
<a:font script="Hans" typeface="等线"/>
<a:font script="Hant" typeface="新細明體"/>
<a:font script="Arab" typeface="Arial"/>
<a:font script="Hebr" typeface="Arial"/>
<a:font script="Thai" typeface="Tahoma"/>
<a:font script="Thai" typeface="Cordia New"/>
<a:font script="Ethi" typeface="Nyala"/>
<a:font script="Beng" typeface="Vrinda"/>
<a:font script="Gujr" typeface="Shruti"/>
@@ -109,6 +126,23 @@
<a:font script="Viet" typeface="Arial"/>
<a:font script="Uigh" typeface="Microsoft Uighur"/>
<a:font script="Geor" typeface="Sylfaen"/>
<a:font script="Armn" typeface="Arial"/>
<a:font script="Bugi" typeface="Leelawadee UI"/>
<a:font script="Bopo" typeface="Microsoft JhengHei"/>
<a:font script="Java" typeface="Javanese Text"/>
<a:font script="Lisu" typeface="Segoe UI"/>
<a:font script="Mymr" typeface="Myanmar Text"/>
<a:font script="Nkoo" typeface="Ebrima"/>
<a:font script="Olck" typeface="Nirmala UI"/>
<a:font script="Osma" typeface="Ebrima"/>
<a:font script="Phag" typeface="Phagspa"/>
<a:font script="Syrn" typeface="Estrangelo Edessa"/>
<a:font script="Syrj" typeface="Estrangelo Edessa"/>
<a:font script="Syre" typeface="Estrangelo Edessa"/>
<a:font script="Sora" typeface="Nirmala UI"/>
<a:font script="Tale" typeface="Microsoft Tai Le"/>
<a:font script="Talu" typeface="Microsoft New Tai Lue"/>
<a:font script="Tfng" typeface="Ebrima"/>
</a:minorFont>
</a:fontScheme>
<a:fmtScheme name="Office">
@@ -120,199 +154,140 @@
<a:gsLst>
<a:gs pos="0">
<a:schemeClr val="phClr">
<a:tint val="50000"/>
<a:satMod val="300000"/>
<a:lumMod val="110000"/>
<a:satMod val="105000"/>
<a:tint val="67000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="35000">
<a:gs pos="50000">
<a:schemeClr val="phClr">
<a:tint val="37000"/>
<a:satMod val="300000"/>
<a:lumMod val="105000"/>
<a:satMod val="103000"/>
<a:tint val="73000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="100000">
<a:schemeClr val="phClr">
<a:tint val="15000"/>
<a:satMod val="350000"/>
<a:lumMod val="105000"/>
<a:satMod val="109000"/>
<a:tint val="81000"/>
</a:schemeClr>
</a:gs>
</a:gsLst>
<a:lin ang="16200000" scaled="1"/>
<a:lin ang="5400000" scaled="0"/>
</a:gradFill>
<a:gradFill rotWithShape="1">
<a:gsLst>
<a:gs pos="0">
<a:schemeClr val="phClr">
<a:tint val="100000"/>
<a:satMod val="103000"/>
<a:lumMod val="102000"/>
<a:tint val="94000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="50000">
<a:schemeClr val="phClr">
<a:satMod val="110000"/>
<a:lumMod val="100000"/>
<a:shade val="100000"/>
<a:satMod val="130000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="100000">
<a:schemeClr val="phClr">
<a:tint val="50000"/>
<a:shade val="100000"/>
<a:satMod val="350000"/>
<a:lumMod val="99000"/>
<a:satMod val="120000"/>
<a:shade val="78000"/>
</a:schemeClr>
</a:gs>
</a:gsLst>
<a:lin ang="16200000" scaled="0"/>
<a:lin ang="5400000" scaled="0"/>
</a:gradFill>
</a:fillStyleLst>
<a:lnStyleLst>
<a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="phClr">
<a:shade val="95000"/>
<a:satMod val="105000"/>
</a:schemeClr>
</a:solidFill>
<a:prstDash val="solid"/>
</a:ln>
<a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">
<a:ln w="6350" cap="flat" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="phClr"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:miter lim="800000"/>
</a:ln>
<a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">
<a:ln w="12700" cap="flat" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="phClr"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:miter lim="800000"/>
</a:ln>
<a:ln w="19050" cap="flat" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="phClr"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:miter lim="800000"/>
</a:ln>
</a:lnStyleLst>
<a:effectStyleLst>
<a:effectStyle>
<a:effectLst>
<a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0">
<a:srgbClr val="000000">
<a:alpha val="38000"/>
</a:srgbClr>
</a:outerShdw>
</a:effectLst>
<a:effectLst/>
</a:effectStyle>
<a:effectStyle>
<a:effectLst/>
</a:effectStyle>
<a:effectStyle>
<a:effectLst>
<a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
<a:outerShdw blurRad="57150" dist="19050" dir="5400000" algn="ctr" rotWithShape="0">
<a:srgbClr val="000000">
<a:alpha val="35000"/>
<a:alpha val="63000"/>
</a:srgbClr>
</a:outerShdw>
</a:effectLst>
</a:effectStyle>
<a:effectStyle>
<a:effectLst>
<a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
<a:srgbClr val="000000">
<a:alpha val="35000"/>
</a:srgbClr>
</a:outerShdw>
</a:effectLst>
<a:scene3d>
<a:camera prst="orthographicFront">
<a:rot lat="0" lon="0" rev="0"/>
</a:camera>
<a:lightRig rig="threePt" dir="t">
<a:rot lat="0" lon="0" rev="1200000"/>
</a:lightRig>
</a:scene3d>
<a:sp3d>
<a:bevelT w="63500" h="25400"/>
</a:sp3d>
</a:effectStyle>
</a:effectStyleLst>
<a:bgFillStyleLst>
<a:solidFill>
<a:schemeClr val="phClr"/>
</a:solidFill>
<a:solidFill>
<a:schemeClr val="phClr">
<a:tint val="95000"/>
<a:satMod val="170000"/>
</a:schemeClr>
</a:solidFill>
<a:gradFill rotWithShape="1">
<a:gsLst>
<a:gs pos="0">
<a:schemeClr val="phClr">
<a:tint val="40000"/>
<a:satMod val="350000"/>
<a:tint val="93000"/>
<a:satMod val="150000"/>
<a:shade val="98000"/>
<a:lumMod val="102000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="40000">
<a:gs pos="50000">
<a:schemeClr val="phClr">
<a:tint val="45000"/>
<a:shade val="99000"/>
<a:satMod val="350000"/>
<a:tint val="98000"/>
<a:satMod val="130000"/>
<a:shade val="90000"/>
<a:lumMod val="103000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="100000">
<a:schemeClr val="phClr">
<a:shade val="20000"/>
<a:satMod val="255000"/>
<a:shade val="63000"/>
<a:satMod val="120000"/>
</a:schemeClr>
</a:gs>
</a:gsLst>
<a:path path="circle">
<a:fillToRect l="50000" t="-80000" r="50000" b="180000"/>
</a:path>
</a:gradFill>
<a:gradFill rotWithShape="1">
<a:gsLst>
<a:gs pos="0">
<a:schemeClr val="phClr">
<a:tint val="80000"/>
<a:satMod val="300000"/>
</a:schemeClr>
</a:gs>
<a:gs pos="100000">
<a:schemeClr val="phClr">
<a:shade val="30000"/>
<a:satMod val="200000"/>
</a:schemeClr>
</a:gs>
</a:gsLst>
<a:path path="circle">
<a:fillToRect l="50000" t="50000" r="50000" b="50000"/>
</a:path>
<a:lin ang="5400000" scaled="0"/>
</a:gradFill>
</a:bgFillStyleLst>
</a:fmtScheme>
</a:themeElements>
<a:objectDefaults>
<a:spDef>
<a:spPr/>
<a:bodyPr/>
<a:lstStyle/>
<a:style>
<a:lnRef idx="1">
<a:schemeClr val="accent1"/>
</a:lnRef>
<a:fillRef idx="3">
<a:schemeClr val="accent1"/>
</a:fillRef>
<a:effectRef idx="2">
<a:schemeClr val="accent1"/>
</a:effectRef>
<a:fontRef idx="minor">
<a:schemeClr val="lt1"/>
</a:fontRef>
</a:style>
</a:spDef>
<a:lnDef>
<a:spPr/>
<a:bodyPr/>
<a:lstStyle/>
<a:style>
<a:lnRef idx="2">
<a:schemeClr val="accent1"/>
</a:lnRef>
<a:fillRef idx="0">
<a:schemeClr val="accent1"/>
</a:fillRef>
<a:effectRef idx="1">
<a:schemeClr val="accent1"/>
</a:effectRef>
<a:fontRef idx="minor">
<a:schemeClr val="tx1"/>
</a:fontRef>
</a:style>
</a:lnDef>
</a:objectDefaults>
<a:objectDefaults/>
<a:extraClrSchemeLst/>
<a:extLst>
<a:ext uri="{05A4C25C-085E-4340-85A3-A5531E510DB2}">
<thm15:themeFamily xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main" name="Office Theme" id="{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}" vid="{4A3C46E8-61CC-4603-A589-7422A47A8E4A}"/>
</a:ext>
</a:extLst>
</a:theme>