1 Star 2 Fork 1

wx-fork/unioffice

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
container.go 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
Todd 提交于 2017-09-09 10:25 +08:00 . spreadsheet: add comment support
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package vmldrawing
import (
"encoding/xml"
"baliance.com/gooxml/schema/urn/schemas_microsoft_com/vml"
)
type Container struct {
Layout *vml.OfcShapelayout
ShapeType *vml.Shapetype
Shape []*vml.Shape
}
func NewContainer() *Container {
return &Container{}
}
func (c *Container) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:v"}, Value: "urn:schemas-microsoft-com:vml"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:o"}, Value: "urn:schemas-microsoft-com:office:office"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:x"}, Value: "urn:schemas-microsoft-com:office:excel"})
start.Name.Local = "xml"
e.EncodeToken(start)
if c.Layout != nil {
se := xml.StartElement{Name: xml.Name{Local: "o:shapelayout"}}
e.EncodeElement(c.Layout, se)
}
if c.ShapeType != nil {
se := xml.StartElement{Name: xml.Name{Local: "v:shapetype"}}
e.EncodeElement(c.ShapeType, se)
}
for _, s := range c.Shape {
se := xml.StartElement{Name: xml.Name{Local: "v:shape"}}
e.EncodeElement(s, se)
}
return e.EncodeToken(xml.EndElement{Name: start.Name})
}
func (c *Container) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
c.Shape = nil
outer:
for {
tok, err := d.Token()
if err != nil {
return err
}
switch el := tok.(type) {
case xml.StartElement:
switch el.Name.Local {
case "shapelayout":
c.Layout = vml.NewOfcShapelayout()
if err := d.DecodeElement(c.Layout, &el); err != nil {
return err
}
case "shapetype":
c.ShapeType = vml.NewShapetype()
if err := d.DecodeElement(c.ShapeType, &el); err != nil {
return err
}
case "shape":
shp := vml.NewShape()
if err := d.DecodeElement(shp, &el); err != nil {
return err
}
c.Shape = append(c.Shape, shp)
}
case xml.EndElement:
break outer
}
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wx-fork/unioffice.git
git@gitee.com:wx-fork/unioffice.git
wx-fork
unioffice
unioffice
v0.7.1

搜索帮助