diff --git a/structsect.go b/structsect.go index fda9d32..3fac075 100644 --- a/structsect.go +++ b/structsect.go @@ -20,6 +20,7 @@ package docx import ( "encoding/xml" "io" + "strconv" "strings" ) @@ -31,8 +32,8 @@ type SectPr struct { // PgSz show the paper size type PgSz struct { - W xml.Attr `xml:"w:w,attr"` // width of paper - H xml.Attr `xml:"w:h,attr"` // high of paper + W int `xml:"w:w,attr"` // width of paper + H int `xml:"w:h,attr"` // high of paper } // UnmarshalXML ... @@ -72,9 +73,15 @@ func (pgsz *PgSz) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { for _, attr := range start.Attr { switch attr.Name.Local { case "w": - pgsz.W = xml.Attr{Name: xml.Name{Local: "w:w"}, Value: attr.Value} + pgsz.W, err = strconv.Atoi(attr.Value) + if err != nil { + return err + } case "h": - pgsz.H = xml.Attr{Name: xml.Name{Local: "w:h"}, Value: attr.Value} + pgsz.H, err = strconv.Atoi(attr.Value) + if err != nil { + return err + } default: // ignore other attributes now } diff --git a/theme.go b/theme.go index 000c0a9..c3f1bb0 100644 --- a/theme.go +++ b/theme.go @@ -21,7 +21,6 @@ package docx import ( - "encoding/xml" "io/fs" ) @@ -42,8 +41,8 @@ func (f *Docx) WithDefaultTheme() *Docx { func (f *Docx) WithA3Page() *Docx { sectpr := &SectPr{ PgSz: &PgSz{ - W: xml.Attr{Name: xml.Name{Local: "w:w"}, Value: "16838"}, - H: xml.Attr{Name: xml.Name{Local: "w:h"}, Value: "23811"}, + W: 16838, + H: 23811, }, } f.Document.Body.Items = append(f.Document.Body.Items, sectpr) @@ -54,8 +53,8 @@ func (f *Docx) WithA3Page() *Docx { func (f *Docx) WithA4Page() *Docx { sectpr := &SectPr{ PgSz: &PgSz{ - W: xml.Attr{Name: xml.Name{Local: "w:w"}, Value: "11906"}, - H: xml.Attr{Name: xml.Name{Local: "w:h"}, Value: "16838"}, + W: 11906, + H: 16838, }, } f.Document.Body.Items = append(f.Document.Body.Items, sectpr)