mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-11 11:04:54 +08:00
add more attrs
This commit is contained in:
@@ -70,6 +70,22 @@ func (c *WordprocessingCanvas) UnmarshalXML(d *xml.Decoder, start xml.StartEleme
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.Items = append(c.Items, &value)
|
c.Items = append(c.Items, &value)
|
||||||
|
case "pic":
|
||||||
|
var value Picture
|
||||||
|
err = d.DecodeElement(&value, &tt)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
value.XMLPIC = getAtt(tt.Attr, "pic")
|
||||||
|
c.Items = append(c.Items, &value)
|
||||||
|
case "wgp":
|
||||||
|
var value WordprocessingGroup
|
||||||
|
value.file = c.file
|
||||||
|
err = d.DecodeElement(&value, &tt)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Items = append(c.Items, &value)
|
||||||
default:
|
default:
|
||||||
err = d.Skip() // skip unsupported tags
|
err = d.Skip() // skip unsupported tags
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -271,3 +271,68 @@ func (r *NonVisualProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
|
|||||||
_, err = d.Token()
|
_, err = d.Token()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spacing ...
|
||||||
|
type Spacing struct {
|
||||||
|
XMLName xml.Name `xml:"w:spacing,omitempty"`
|
||||||
|
|
||||||
|
Line int `xml:"w:line,attr"`
|
||||||
|
LineRule string `xml:"w:lineRule,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalXML ...
|
||||||
|
func (s *Spacing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
|
||||||
|
for _, attr := range start.Attr {
|
||||||
|
switch attr.Name.Local {
|
||||||
|
case "line":
|
||||||
|
s.Line, err = strconv.Atoi(attr.Value)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "lineRule":
|
||||||
|
s.LineRule = attr.Value
|
||||||
|
default:
|
||||||
|
// ignore other attributes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Consume the end element
|
||||||
|
_, err = d.Token()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ind ...
|
||||||
|
type Ind struct {
|
||||||
|
XMLName xml.Name `xml:"w:ind,omitempty"`
|
||||||
|
|
||||||
|
FirstLineChars int `xml:"w:firstLineChars,attr"`
|
||||||
|
FirstLine int `xml:"w:firstLine,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalXML ...
|
||||||
|
func (i *Ind) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
|
||||||
|
for _, attr := range start.Attr {
|
||||||
|
switch attr.Name.Local {
|
||||||
|
case "firstLineChars":
|
||||||
|
if attr.Value == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i.FirstLineChars, err = strconv.Atoi(attr.Value)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "firstLine":
|
||||||
|
if attr.Value == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i.FirstLine, err = strconv.Atoi(attr.Value)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// ignore other attributes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Consume the end element
|
||||||
|
_, err = d.Token()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import (
|
|||||||
// ParagraphProperties <w:pPr>
|
// ParagraphProperties <w:pPr>
|
||||||
type ParagraphProperties struct {
|
type ParagraphProperties struct {
|
||||||
XMLName xml.Name `xml:"w:pPr,omitempty"`
|
XMLName xml.Name `xml:"w:pPr,omitempty"`
|
||||||
|
Spacing *Spacing
|
||||||
|
Ind *Ind
|
||||||
Justification *Justification
|
Justification *Justification
|
||||||
Shade *Shade
|
Shade *Shade
|
||||||
Kern *Kern
|
Kern *Kern
|
||||||
@@ -57,6 +59,20 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
|
|||||||
}
|
}
|
||||||
if tt, ok := t.(xml.StartElement); ok {
|
if tt, ok := t.(xml.StartElement); ok {
|
||||||
switch tt.Name.Local {
|
switch tt.Name.Local {
|
||||||
|
case "spacing":
|
||||||
|
var value Spacing
|
||||||
|
err = d.DecodeElement(&value, &tt)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.Spacing = &value
|
||||||
|
case "ind":
|
||||||
|
var value Ind
|
||||||
|
err = d.DecodeElement(&value, &tt)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.Ind = &value
|
||||||
case "jc":
|
case "jc":
|
||||||
p.Justification = &Justification{Val: getAtt(tt.Attr, "val")}
|
p.Justification = &Justification{Val: getAtt(tt.Attr, "val")}
|
||||||
case "shd":
|
case "shd":
|
||||||
@@ -183,6 +199,8 @@ func (p *Paragraph) String() string {
|
|||||||
sb.WriteString(x.Text)
|
sb.WriteString(x.Text)
|
||||||
case *Tab:
|
case *Tab:
|
||||||
sb.WriteByte('\t')
|
sb.WriteByte('\t')
|
||||||
|
case *BarterRabbet:
|
||||||
|
sb.WriteByte('\n')
|
||||||
case *Drawing:
|
case *Drawing:
|
||||||
if x.Inline != nil && x.Inline.Graphic != nil && x.Inline.Graphic.GraphicData != nil {
|
if x.Inline != nil && x.Inline.Graphic != nil && x.Inline.Graphic.GraphicData != nil {
|
||||||
if x.Inline.Graphic.GraphicData.Pic != nil {
|
if x.Inline.Graphic.GraphicData.Pic != nil {
|
||||||
|
|||||||
21
structrun.go
21
structrun.go
@@ -31,6 +31,8 @@ import (
|
|||||||
// a piece of text in bold, or a link
|
// a piece of text in bold, or a link
|
||||||
type Run struct {
|
type Run struct {
|
||||||
XMLName xml.Name `xml:"w:r,omitempty"`
|
XMLName xml.Name `xml:"w:r,omitempty"`
|
||||||
|
Space string `xml:"xml:space,attr,omitempty"`
|
||||||
|
RsidR string `xml:"w:rsidR,attr,omitempty"`
|
||||||
RsidRPr string `xml:"w:rsidRPr,attr,omitempty"`
|
RsidRPr string `xml:"w:rsidRPr,attr,omitempty"`
|
||||||
|
|
||||||
RunProperties *RunProperties `xml:"w:rPr,omitempty"`
|
RunProperties *RunProperties `xml:"w:rPr,omitempty"`
|
||||||
@@ -46,6 +48,10 @@ type Run struct {
|
|||||||
func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
for _, attr := range start.Attr {
|
for _, attr := range start.Attr {
|
||||||
switch attr.Name.Local {
|
switch attr.Name.Local {
|
||||||
|
case "space":
|
||||||
|
r.Space = attr.Value
|
||||||
|
case "rsidR":
|
||||||
|
r.RsidR = attr.Value
|
||||||
case "rsidRPr":
|
case "rsidRPr":
|
||||||
r.RsidRPr = attr.Value
|
r.RsidRPr = attr.Value
|
||||||
default:
|
default:
|
||||||
@@ -110,6 +116,8 @@ func (r *Run) parse(d *xml.Decoder, tt xml.StartElement) (child interface{}, err
|
|||||||
child = &value
|
child = &value
|
||||||
case "tab":
|
case "tab":
|
||||||
child = &Tab{}
|
child = &Tab{}
|
||||||
|
case "br":
|
||||||
|
child = &BarterRabbet{}
|
||||||
case "AlternateContent":
|
case "AlternateContent":
|
||||||
/*var value AlternateContent
|
/*var value AlternateContent
|
||||||
value.file = r.file
|
value.file = r.file
|
||||||
@@ -174,7 +182,6 @@ type RunProperties struct {
|
|||||||
Bold *Bold
|
Bold *Bold
|
||||||
ICs *struct{} `xml:"w:iCs,omitempty"`
|
ICs *struct{} `xml:"w:iCs,omitempty"`
|
||||||
Italic *Italic
|
Italic *Italic
|
||||||
Underline *Underline
|
|
||||||
Highlight *Highlight
|
Highlight *Highlight
|
||||||
Color *Color
|
Color *Color
|
||||||
Size *Size
|
Size *Size
|
||||||
@@ -183,6 +190,7 @@ type RunProperties struct {
|
|||||||
Style *Style
|
Style *Style
|
||||||
Shade *Shade
|
Shade *Shade
|
||||||
Kern *Kern
|
Kern *Kern
|
||||||
|
Underline *Underline
|
||||||
VertAlign *VertAlign
|
VertAlign *VertAlign
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,10 +285,11 @@ func (r *RunProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
|
|||||||
|
|
||||||
// RunFonts specifies the fonts used in the text of a run.
|
// RunFonts specifies the fonts used in the text of a run.
|
||||||
type RunFonts struct {
|
type RunFonts struct {
|
||||||
XMLName xml.Name `xml:"w:rFonts,omitempty"`
|
XMLName xml.Name `xml:"w:rFonts,omitempty"`
|
||||||
ASCII string `xml:"w:ascii,attr,omitempty"`
|
ASCII string `xml:"w:ascii,attr,omitempty"`
|
||||||
HAnsi string `xml:"w:hAnsi,attr,omitempty"`
|
EastAsia string `xml:"w:eastAsia,attr,omitempty"`
|
||||||
Hint string `xml:"w:hint,attr,omitempty"`
|
HAnsi string `xml:"w:hAnsi,attr,omitempty"`
|
||||||
|
Hint string `xml:"w:hint,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalXML ...
|
// UnmarshalXML ...
|
||||||
@@ -289,6 +298,8 @@ func (f *RunFonts) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|||||||
switch attr.Name.Local {
|
switch attr.Name.Local {
|
||||||
case "ascii":
|
case "ascii":
|
||||||
f.ASCII = attr.Value
|
f.ASCII = attr.Value
|
||||||
|
case "eastAsia":
|
||||||
|
f.EastAsia = attr.Value
|
||||||
case "hAnsi":
|
case "hAnsi":
|
||||||
f.HAnsi = attr.Value
|
f.HAnsi = attr.Value
|
||||||
case "hint":
|
case "hint":
|
||||||
|
|||||||
@@ -621,16 +621,16 @@ func (c *WTextBoxContent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
|
|||||||
// WPSBodyPr represents the body properties for a WordprocessingML DrawingML shape.
|
// WPSBodyPr represents the body properties for a WordprocessingML DrawingML shape.
|
||||||
type WPSBodyPr struct {
|
type WPSBodyPr struct {
|
||||||
XMLName xml.Name `xml:"wps:bodyPr,omitempty"`
|
XMLName xml.Name `xml:"wps:bodyPr,omitempty"`
|
||||||
Rot int `xml:"rot,attr,omitempty"`
|
Rot int `xml:"rot,attr"`
|
||||||
Vert string `xml:"vert,attr,omitempty"`
|
Vert string `xml:"vert,attr,omitempty"`
|
||||||
Wrap string `xml:"wrap,attr,omitempty"`
|
Wrap string `xml:"wrap,attr,omitempty"`
|
||||||
LIns int64 `xml:"lIns,attr,omitempty"`
|
LIns int64 `xml:"lIns,attr"`
|
||||||
TIns int64 `xml:"tIns,attr,omitempty"`
|
TIns int64 `xml:"tIns,attr"`
|
||||||
RIns int64 `xml:"rIns,attr,omitempty"`
|
RIns int64 `xml:"rIns,attr"`
|
||||||
BIns int64 `xml:"bIns,attr,omitempty"`
|
BIns int64 `xml:"bIns,attr"`
|
||||||
Anchor string `xml:"anchor,attr,omitempty"`
|
Anchor string `xml:"anchor,attr,omitempty"`
|
||||||
AnchorCtr int `xml:"anchorCtr,attr,omitempty"`
|
AnchorCtr int `xml:"anchorCtr,attr"`
|
||||||
Upright int `xml:"upright,attr,omitempty"`
|
Upright int `xml:"upright,attr"`
|
||||||
|
|
||||||
NoAutofit *struct{} `xml:"a:noAutofit,omitempty"`
|
NoAutofit *struct{} `xml:"a:noAutofit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,17 +30,30 @@ type Tab struct {
|
|||||||
XMLName xml.Name `xml:"w:tab,omitempty"`
|
XMLName xml.Name `xml:"w:tab,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BarterRabbet is <br>
|
||||||
|
type BarterRabbet struct {
|
||||||
|
XMLName xml.Name `xml:"w:br,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Text object contains the actual text
|
// Text object contains the actual text
|
||||||
type Text struct {
|
type Text struct {
|
||||||
XMLName xml.Name `xml:"w:t,omitempty"`
|
XMLName xml.Name `xml:"w:t,omitempty"`
|
||||||
|
|
||||||
// XMLSpace string `xml:"xml:space,attr,omitempty"`
|
XMLSpace string `xml:"xml:space,attr,omitempty"`
|
||||||
|
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalXML ...
|
// UnmarshalXML ...
|
||||||
func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
|
for _, attr := range start.Attr {
|
||||||
|
switch attr.Name.Local {
|
||||||
|
case "space":
|
||||||
|
r.XMLSpace = attr.Value
|
||||||
|
default:
|
||||||
|
// ignore other attributes
|
||||||
|
}
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
t, err := d.Token()
|
t, err := d.Token()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
|||||||
Reference in New Issue
Block a user