mirror of
https://github.com/fumiama/go-docx.git
synced 2026-07-01 00:20:24 +08:00
fix(structtable): add float fallback when parsing numeric value (#10)
This commit is contained in:
@@ -392,7 +392,11 @@ func (g *WGridCol) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err err
|
||||
case "w":
|
||||
g.W, err = strconv.ParseInt(attr.Value, 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
w, err := strconv.ParseFloat(attr.Value, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g.W = int64(w)
|
||||
}
|
||||
default:
|
||||
// ignore other attributes
|
||||
@@ -493,9 +497,13 @@ func (t *WTableRowProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) e
|
||||
switch attr.Name.Local {
|
||||
case "val":
|
||||
th.Val, err = strconv.ParseInt(attr.Value, 10, 64)
|
||||
if err != nil {
|
||||
w, err := strconv.ParseFloat(attr.Value, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
th.Val = int64(w)
|
||||
}
|
||||
case "hRule":
|
||||
th.Rule = attr.Value
|
||||
}
|
||||
@@ -616,9 +624,13 @@ func (r *WTableCellProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement)
|
||||
continue
|
||||
}
|
||||
r.TableCellWidth.W, err = strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
w, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.TableCellWidth.W = int64(w)
|
||||
}
|
||||
r.TableCellWidth.Type = getAtt(tt.Attr, "type")
|
||||
case "vMerge":
|
||||
r.VMerge = &WvMerge{Val: getAtt(tt.Attr, "val")}
|
||||
|
||||
Reference in New Issue
Block a user