2024-01-09 20:56:20 +08:00
|
|
|
// Copyright 2016 - 2024 The excelize Authors. All rights reserved. Use of
|
2018-09-14 00:44:23 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
2022-02-17 00:09:11 +08:00
|
|
|
// Package excelize providing a set of functions that allow you to write to and
|
|
|
|
// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
|
|
|
|
// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
|
|
|
|
// Supports complex components by high compatibility, and provided streaming
|
|
|
|
// API for generating or reading data from a worksheet with huge amounts of
|
2024-01-18 15:31:43 +08:00
|
|
|
// data. This library needs Go version 1.18 or later.
|
2018-09-14 00:58:48 +08:00
|
|
|
|
2017-05-13 13:28:21 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
|
|
|
// vmlDrawing directly maps the root element in the file
|
|
|
|
// xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type vmlDrawing struct {
|
|
|
|
XMLName xml.Name `xml:"xml"`
|
|
|
|
XMLNSv string `xml:"xmlns:v,attr"`
|
|
|
|
XMLNSo string `xml:"xmlns:o,attr"`
|
|
|
|
XMLNSx string `xml:"xmlns:x,attr"`
|
|
|
|
XMLNSmv string `xml:"xmlns:mv,attr"`
|
2023-07-11 23:43:45 +08:00
|
|
|
ShapeLayout *xlsxShapeLayout `xml:"o:shapelayout"`
|
|
|
|
ShapeType *xlsxShapeType `xml:"v:shapetype"`
|
2017-05-13 13:28:21 +08:00
|
|
|
Shape []xlsxShape `xml:"v:shape"`
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:43:45 +08:00
|
|
|
// xlsxShapeLayout directly maps the shapelayout element. This element contains
|
2017-05-13 13:28:21 +08:00
|
|
|
// child elements that store information used in the editing and layout of
|
|
|
|
// shapes.
|
2023-07-11 23:43:45 +08:00
|
|
|
type xlsxShapeLayout struct {
|
2017-05-13 13:28:21 +08:00
|
|
|
Ext string `xml:"v:ext,attr"`
|
|
|
|
IDmap *xlsxIDmap `xml:"o:idmap"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxIDmap directly maps the idmap element.
|
|
|
|
type xlsxIDmap struct {
|
|
|
|
Ext string `xml:"v:ext,attr"`
|
|
|
|
Data int `xml:"data,attr"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxShape directly maps the shape element.
|
|
|
|
type xlsxShape struct {
|
|
|
|
XMLName xml.Name `xml:"v:shape"`
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
Type string `xml:"type,attr"`
|
|
|
|
Style string `xml:"style,attr"`
|
2023-07-11 23:43:45 +08:00
|
|
|
Button string `xml:"o:button,attr,omitempty"`
|
|
|
|
Filled string `xml:"filled,attr,omitempty"`
|
2023-07-21 00:03:37 +08:00
|
|
|
FillColor string `xml:"fillcolor,attr,omitempty"`
|
2023-07-11 23:43:45 +08:00
|
|
|
InsetMode string `xml:"urn:schemas-microsoft-com:office:office insetmode,attr,omitempty"`
|
|
|
|
Stroked string `xml:"stroked,attr,omitempty"`
|
|
|
|
StrokeColor string `xml:"strokecolor,attr,omitempty"`
|
2017-05-13 13:28:21 +08:00
|
|
|
Val string `xml:",innerxml"`
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:43:45 +08:00
|
|
|
// xlsxShapeType directly maps the shapetype element.
|
|
|
|
type xlsxShapeType struct {
|
2017-05-13 13:28:21 +08:00
|
|
|
ID string `xml:"id,attr"`
|
2023-07-11 23:43:45 +08:00
|
|
|
CoordSize string `xml:"coordsize,attr"`
|
2017-05-13 13:28:21 +08:00
|
|
|
Spt int `xml:"o:spt,attr"`
|
|
|
|
Path string `xml:"path,attr"`
|
|
|
|
Stroke *xlsxStroke `xml:"v:stroke"`
|
|
|
|
VPath *vPath `xml:"v:path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxStroke directly maps the stroke element.
|
|
|
|
type xlsxStroke struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
JoinStyle string `xml:"joinstyle,attr"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// vPath directly maps the v:path element.
|
|
|
|
type vPath struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
GradientShapeOK string `xml:"gradientshapeok,attr,omitempty"`
|
|
|
|
ConnectType string `xml:"o:connecttype,attr"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// vFill directly maps the v:fill element. This element must be defined within a
|
|
|
|
// Shape element.
|
|
|
|
type vFill struct {
|
|
|
|
Angle int `xml:"angle,attr,omitempty"`
|
|
|
|
Color2 string `xml:"color2,attr"`
|
|
|
|
Type string `xml:"type,attr,omitempty"`
|
|
|
|
Fill *oFill `xml:"o:fill"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// oFill directly maps the o:fill element.
|
|
|
|
type oFill struct {
|
|
|
|
Ext string `xml:"v:ext,attr"`
|
|
|
|
Type string `xml:"type,attr,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// vShadow directly maps the v:shadow element. This element must be defined
|
|
|
|
// within a Shape element. In addition, the On attribute must be set to True.
|
|
|
|
type vShadow struct {
|
|
|
|
On string `xml:"on,attr"`
|
|
|
|
Color string `xml:"color,attr,omitempty"`
|
|
|
|
Obscured string `xml:"obscured,attr"`
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:43:45 +08:00
|
|
|
// vTextBox directly maps the v:textbox element. This element must be defined
|
2017-05-13 13:28:21 +08:00
|
|
|
// within a Shape element.
|
2023-07-11 23:43:45 +08:00
|
|
|
type vTextBox struct {
|
2017-05-13 13:28:21 +08:00
|
|
|
Style string `xml:"style,attr"`
|
|
|
|
Div *xlsxDiv `xml:"div"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxDiv directly maps the div element.
|
|
|
|
type xlsxDiv struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
Style string `xml:"style,attr"`
|
|
|
|
Font []vmlFont `xml:"font"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type vmlFont struct {
|
|
|
|
Face string `xml:"face,attr,omitempty"`
|
|
|
|
Size uint `xml:"size,attr,omitempty"`
|
|
|
|
Color string `xml:"color,attr,omitempty"`
|
|
|
|
Content string `xml:",innerxml"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xClientData (Attached Object Data) directly maps the x:ClientData element.
|
|
|
|
// This element specifies data associated with objects attached to a
|
|
|
|
// spreadsheet. While this element might contain any of the child elements
|
|
|
|
// below, only certain combinations are meaningful. The ObjectType attribute
|
|
|
|
// determines the kind of object the element represents and which subset of
|
|
|
|
// child elements is appropriate. Relevant groups are identified for each child
|
|
|
|
// element.
|
|
|
|
type xClientData struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
ObjectType string `xml:"ObjectType,attr"`
|
2023-07-21 00:03:37 +08:00
|
|
|
MoveWithCells *string `xml:"x:MoveWithCells"`
|
|
|
|
SizeWithCells *string `xml:"x:SizeWithCells"`
|
2023-07-11 23:43:45 +08:00
|
|
|
Anchor string `xml:"x:Anchor"`
|
2023-07-21 00:03:37 +08:00
|
|
|
Locked string `xml:"x:Locked,omitempty"`
|
|
|
|
PrintObject string `xml:"x:PrintObject,omitempty"`
|
|
|
|
AutoFill string `xml:"x:AutoFill,omitempty"`
|
2023-07-11 23:43:45 +08:00
|
|
|
FmlaMacro string `xml:"x:FmlaMacro,omitempty"`
|
|
|
|
TextHAlign string `xml:"x:TextHAlign,omitempty"`
|
|
|
|
TextVAlign string `xml:"x:TextVAlign,omitempty"`
|
2023-07-31 00:08:10 +08:00
|
|
|
Row *int `xml:"x:Row"`
|
|
|
|
Column *int `xml:"x:Column"`
|
2023-07-21 00:03:37 +08:00
|
|
|
Checked int `xml:"x:Checked,omitempty"`
|
|
|
|
FmlaLink string `xml:"x:FmlaLink,omitempty"`
|
|
|
|
NoThreeD *string `xml:"x:NoThreeD"`
|
|
|
|
FirstButton *string `xml:"x:FirstButton"`
|
|
|
|
Val uint `xml:"x:Val,omitempty"`
|
|
|
|
Min uint `xml:"x:Min,omitempty"`
|
|
|
|
Max uint `xml:"x:Max,omitempty"`
|
|
|
|
Inc uint `xml:"x:Inc,omitempty"`
|
|
|
|
Page uint `xml:"x:Page,omitempty"`
|
|
|
|
Horiz *string `xml:"x:Horiz"`
|
|
|
|
Dx uint `xml:"x:Dx,omitempty"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVmlDrawing defines the structure used to parse the file
|
|
|
|
// xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type decodeVmlDrawing struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
ShapeType decodeShapeType `xml:"urn:schemas-microsoft-com:vml shapetype"`
|
|
|
|
Shape []decodeShape `xml:"urn:schemas-microsoft-com:vml shape"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeShapeType defines the structure used to parse the shapetype element in
|
|
|
|
// the file xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type decodeShapeType struct {
|
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
CoordSize string `xml:"coordsize,attr"`
|
|
|
|
Spt int `xml:"spt,attr"`
|
|
|
|
Path string `xml:"path,attr"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// decodeShape defines the structure used to parse the particular shape element.
|
|
|
|
type decodeShape struct {
|
2023-07-11 23:43:45 +08:00
|
|
|
ID string `xml:"id,attr"`
|
|
|
|
Type string `xml:"type,attr"`
|
|
|
|
Style string `xml:"style,attr"`
|
|
|
|
Button string `xml:"button,attr,omitempty"`
|
|
|
|
Filled string `xml:"filled,attr,omitempty"`
|
2023-07-21 00:03:37 +08:00
|
|
|
FillColor string `xml:"fillcolor,attr,omitempty"`
|
2023-07-11 23:43:45 +08:00
|
|
|
InsetMode string `xml:"urn:schemas-microsoft-com:office:office insetmode,attr,omitempty"`
|
|
|
|
Stroked string `xml:"stroked,attr,omitempty"`
|
|
|
|
StrokeColor string `xml:"strokecolor,attr,omitempty"`
|
|
|
|
Val string `xml:",innerxml"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
2023-07-13 00:03:24 +08:00
|
|
|
// decodeShapeVal defines the structure used to parse the sub-element of the
|
|
|
|
// shape in the file xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type decodeShapeVal struct {
|
2023-07-31 00:08:10 +08:00
|
|
|
TextBox decodeVMLTextBox `xml:"textbox"`
|
2023-07-13 00:03:24 +08:00
|
|
|
ClientData decodeVMLClientData `xml:"ClientData"`
|
|
|
|
}
|
|
|
|
|
2023-07-31 00:08:10 +08:00
|
|
|
// decodeVMLFontU defines the structure used to parse the u element in the VML.
|
|
|
|
type decodeVMLFontU struct {
|
|
|
|
Class string `xml:"class,attr"`
|
|
|
|
Val string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVMLFontI defines the structure used to parse the i element in the VML.
|
|
|
|
type decodeVMLFontI struct {
|
|
|
|
U *decodeVMLFontU `xml:"u"`
|
|
|
|
Val string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVMLFontB defines the structure used to parse the b element in the VML.
|
|
|
|
type decodeVMLFontB struct {
|
|
|
|
I *decodeVMLFontI `xml:"i"`
|
|
|
|
U *decodeVMLFontU `xml:"u"`
|
|
|
|
Val string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVMLFont defines the structure used to parse the font element in the VML.
|
|
|
|
type decodeVMLFont struct {
|
|
|
|
Face string `xml:"face,attr,omitempty"`
|
|
|
|
Size uint `xml:"size,attr,omitempty"`
|
|
|
|
Color string `xml:"color,attr,omitempty"`
|
|
|
|
B *decodeVMLFontB `xml:"b"`
|
|
|
|
I *decodeVMLFontI `xml:"i"`
|
|
|
|
U *decodeVMLFontU `xml:"u"`
|
|
|
|
Val string `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVMLDiv defines the structure used to parse the div element in the VML.
|
|
|
|
type decodeVMLDiv struct {
|
|
|
|
Font []decodeVMLFont `xml:"font"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// decodeVMLTextBox defines the structure used to parse the v:textbox element in
|
|
|
|
// the file xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type decodeVMLTextBox struct {
|
|
|
|
Div decodeVMLDiv `xml:"div"`
|
|
|
|
}
|
|
|
|
|
2023-07-13 00:03:24 +08:00
|
|
|
// decodeVMLClientData defines the structure used to parse the x:ClientData
|
|
|
|
// element in the file xl/drawings/vmlDrawing%d.vml.
|
|
|
|
type decodeVMLClientData struct {
|
|
|
|
ObjectType string `xml:"ObjectType,attr"`
|
2023-07-31 00:08:10 +08:00
|
|
|
Anchor string
|
2023-07-28 00:24:08 +08:00
|
|
|
FmlaMacro string
|
2023-07-31 00:08:10 +08:00
|
|
|
Column *int
|
|
|
|
Row *int
|
2023-07-28 00:24:08 +08:00
|
|
|
Checked int
|
|
|
|
FmlaLink string
|
|
|
|
Val uint
|
|
|
|
Min uint
|
|
|
|
Max uint
|
|
|
|
Inc uint
|
|
|
|
Page uint
|
|
|
|
Horiz *string
|
2023-07-13 00:03:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-13 13:28:21 +08:00
|
|
|
// encodeShape defines the structure used to re-serialization shape element.
|
|
|
|
type encodeShape struct {
|
|
|
|
Fill *vFill `xml:"v:fill"`
|
|
|
|
Shadow *vShadow `xml:"v:shadow"`
|
|
|
|
Path *vPath `xml:"v:path"`
|
2023-07-11 23:43:45 +08:00
|
|
|
TextBox *vTextBox `xml:"v:textbox"`
|
2017-05-13 13:28:21 +08:00
|
|
|
ClientData *xClientData `xml:"x:ClientData"`
|
|
|
|
}
|
2023-07-11 23:43:45 +08:00
|
|
|
|
2023-07-21 00:03:37 +08:00
|
|
|
// formCtrlPreset defines the structure used to form control presets.
|
|
|
|
type formCtrlPreset struct {
|
|
|
|
autoFill string
|
|
|
|
fill *vFill
|
|
|
|
fillColor string
|
|
|
|
filled string
|
|
|
|
firstButton *string
|
|
|
|
noThreeD *string
|
|
|
|
objectType string
|
|
|
|
shadow *vShadow
|
|
|
|
strokeButton string
|
|
|
|
strokeColor string
|
|
|
|
stroked string
|
|
|
|
textHAlign string
|
|
|
|
textVAlign string
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:43:45 +08:00
|
|
|
// vmlOptions defines the structure used to internal comments and form controls.
|
|
|
|
type vmlOptions struct {
|
2023-07-21 00:03:37 +08:00
|
|
|
formCtrl bool
|
|
|
|
sheet string
|
|
|
|
Comment
|
|
|
|
FormControl
|
2023-07-11 23:43:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FormControl directly maps the form controls information.
|
|
|
|
type FormControl struct {
|
2023-07-21 00:03:37 +08:00
|
|
|
Cell string
|
|
|
|
Macro string
|
|
|
|
Width uint
|
|
|
|
Height uint
|
|
|
|
Checked bool
|
|
|
|
CurrentVal uint
|
|
|
|
MinVal uint
|
|
|
|
MaxVal uint
|
|
|
|
IncChange uint
|
|
|
|
PageChange uint
|
|
|
|
Horizontally bool
|
|
|
|
CellLink string
|
|
|
|
Text string
|
|
|
|
Paragraph []RichTextRun
|
|
|
|
Type FormControlType
|
|
|
|
Format GraphicOptions
|
2023-07-11 23:43:45 +08:00
|
|
|
}
|