From e3d6e419d57c4faced5bac57ec784872a669c222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:08:40 +0800 Subject: [PATCH] fix: empty para in tablecell --- empty.go | 2 + structdoc.go | 10 +- structrun.go | 13 ++ structshape.go | 6 +- structtable.go | 10 +- unpack.go | 2 + xml/a4/word/styles.xml | 43 ++++-- xml/a4/word/theme/theme1.xml | 261 ++++++++++++++++------------------- 8 files changed, 178 insertions(+), 169 deletions(-) diff --git a/empty.go b/empty.go index 71509b5..b025a39 100644 --- a/empty.go +++ b/empty.go @@ -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), diff --git a/structdoc.go b/structdoc.go index 696d7ad..5d7a852 100644 --- a/structdoc.go +++ b/structdoc.go @@ -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"` } diff --git a/structrun.go b/structrun.go index 38e82cc..614d324 100644 --- a/structrun.go +++ b/structrun.go @@ -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() diff --git a/structshape.go b/structshape.go index 47c7bed..388b73d 100644 --- a/structshape.go +++ b/structshape.go @@ -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 { diff --git a/structtable.go b/structtable.go index 3ae1b71..63333b4 100644 --- a/structtable.go +++ b/structtable.go @@ -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"` } diff --git a/unpack.go b/unpack.go index 7aa3685..da17c81 100644 --- a/unpack.go +++ b/unpack.go @@ -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 diff --git a/xml/a4/word/styles.xml b/xml/a4/word/styles.xml index 63a022e..714439c 100644 --- a/xml/a4/word/styles.xml +++ b/xml/a4/word/styles.xml @@ -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"> - + - + @@ -116,7 +115,7 @@ - + @@ -402,12 +401,13 @@ - + + - + @@ -437,15 +437,28 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + - - + \ No newline at end of file diff --git a/xml/a4/word/theme/theme1.xml b/xml/a4/word/theme/theme1.xml index 2bb59b7..b24868c 100644 --- a/xml/a4/word/theme/theme1.xml +++ b/xml/a4/word/theme/theme1.xml @@ -1,5 +1,5 @@ - + @@ -9,48 +9,48 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -74,18 +74,35 @@ + + + + + + + + + + + + + + + + + - + - + - + - + @@ -109,6 +126,23 @@ + + + + + + + + + + + + + + + + + @@ -120,199 +154,140 @@ - - + + + - + - - + + + - - + + + - + - + + + + + + + + + - - - - + + + - + - - - - - - - - - - + + - + + + + + + + + + - - - - - - - + + + + - + - + - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + + + - + - - - + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + \ No newline at end of file