xmlWorksheet.go 29.9 KB
Newer Older
xurime's avatar
xurime 已提交
1
// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of
xurime's avatar
xurime 已提交
2 3 4 5 6 7 8
// this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//
// Package excelize providing a set of functions that allow you to write to
// and read from XLSX files. Support reads and writes XLSX file generated by
// Microsoft Excel™ 2007 and later. Support save file without losing original
// charts of XLSX. This library needs Go version 1.8 or later.
xurime's avatar
xurime 已提交
9

xurime's avatar
xurime 已提交
10 11
package excelize

12
import "encoding/xml"
xurime's avatar
xurime 已提交
13 14

// xlsxWorksheet directly maps the worksheet element in the namespace
15 16
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
17
type xlsxWorksheet struct {
18 19 20 21 22 23 24 25
	XMLName               xml.Name                     `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
	SheetPr               *xlsxSheetPr                 `xml:"sheetPr"`
	Dimension             xlsxDimension                `xml:"dimension"`
	SheetViews            xlsxSheetViews               `xml:"sheetViews,omitempty"`
	SheetFormatPr         *xlsxSheetFormatPr           `xml:"sheetFormatPr"`
	Cols                  *xlsxCols                    `xml:"cols,omitempty"`
	SheetData             xlsxSheetData                `xml:"sheetData"`
	SheetProtection       *xlsxSheetProtection         `xml:"sheetProtection"`
26
	AutoFilter            *xlsxAutoFilter              `xml:"autoFilter"`
27 28
	MergeCells            *xlsxMergeCells              `xml:"mergeCells"`
	PhoneticPr            *xlsxPhoneticPr              `xml:"phoneticPr"`
29
	ConditionalFormatting []*xlsxConditionalFormatting `xml:"conditionalFormatting"`
30
	DataValidations       *xlsxDataValidations         `xml:"dataValidations,omitempty"`
31 32 33 34 35 36 37 38 39 40
	Hyperlinks            *xlsxHyperlinks              `xml:"hyperlinks"`
	PrintOptions          *xlsxPrintOptions            `xml:"printOptions"`
	PageMargins           *xlsxPageMargins             `xml:"pageMargins"`
	PageSetUp             *xlsxPageSetUp               `xml:"pageSetup"`
	HeaderFooter          *xlsxHeaderFooter            `xml:"headerFooter"`
	Drawing               *xlsxDrawing                 `xml:"drawing"`
	LegacyDrawing         *xlsxLegacyDrawing           `xml:"legacyDrawing"`
	Picture               *xlsxPicture                 `xml:"picture"`
	TableParts            *xlsxTableParts              `xml:"tableParts"`
	ExtLst                *xlsxExtLst                  `xml:"extLst"`
xurime's avatar
xurime 已提交
41 42
}

xurime's avatar
xurime 已提交
43
// xlsxDrawing change r:id to rid in the namespace.
xurime's avatar
xurime 已提交
44
type xlsxDrawing struct {
45
	RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
xurime's avatar
xurime 已提交
46 47 48
}

// xlsxHeaderFooter directly maps the headerFooter element in the namespace
49 50 51 52 53 54
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - When printed or
// viewed in page layout view (§18.18.69), each page of a worksheet can have a
// page header, a page footer, or both. The headers and footers on odd-numbered
// pages can differ from those on even-numbered pages, and the headers and
// footers on the first page can differ from those on odd- and even-numbered
// pages. In the latter case, the first page is not considered an odd page.
xurime's avatar
xurime 已提交
55
type xlsxHeaderFooter struct {
56 57 58 59
	DifferentFirst   bool             `xml:"differentFirst,attr,omitempty"`
	DifferentOddEven bool             `xml:"differentOddEven,attr,omitempty"`
	OddHeader        []*xlsxOddHeader `xml:"oddHeader"`
	OddFooter        []*xlsxOddFooter `xml:"oddFooter"`
xurime's avatar
xurime 已提交
60 61 62
}

// xlsxOddHeader directly maps the oddHeader element in the namespace
63 64
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
65 66 67 68 69
type xlsxOddHeader struct {
	Content string `xml:",chardata"`
}

// xlsxOddFooter directly maps the oddFooter element in the namespace
70 71
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
72 73 74 75 76
type xlsxOddFooter struct {
	Content string `xml:",chardata"`
}

// xlsxPageSetUp directly maps the pageSetup element in the namespace
77 78
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
// settings for the worksheet.
xurime's avatar
xurime 已提交
79
type xlsxPageSetUp struct {
80
	BlackAndWhite      bool    `xml:"blackAndWhite,attr,omitempty"`
xurime's avatar
xurime 已提交
81
	CellComments       string  `xml:"cellComments,attr,omitempty"`
82 83 84 85
	Copies             int     `xml:"copies,attr,omitempty"`
	Draft              bool    `xml:"draft,attr,omitempty"`
	Errors             string  `xml:"errors,attr,omitempty"`
	FirstPageNumber    int     `xml:"firstPageNumber,attr,omitempty"`
86
	FitToHeight        *int    `xml:"fitToHeight,attr"`
87 88 89 90 91
	FitToWidth         int     `xml:"fitToWidth,attr,omitempty"`
	HorizontalDPI      float32 `xml:"horizontalDpi,attr,omitempty"`
	RID                string  `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
	Orientation        string  `xml:"orientation,attr,omitempty"`
	PageOrder          string  `xml:"pageOrder,attr,omitempty"`
92
	PaperHeight        string  `xml:"paperHeight,attr,omitempty"`
93
	PaperSize          int     `xml:"paperSize,attr,omitempty"`
94 95 96 97 98
	PaperWidth         string  `xml:"paperWidth,attr,omitempty"`
	Scale              int     `xml:"scale,attr,omitempty"`
	UseFirstPageNumber bool    `xml:"useFirstPageNumber,attr,omitempty"`
	UsePrinterDefaults bool    `xml:"usePrinterDefaults,attr,omitempty"`
	VerticalDPI        float32 `xml:"verticalDpi,attr,omitempty"`
xurime's avatar
xurime 已提交
99 100 101
}

// xlsxPrintOptions directly maps the printOptions element in the namespace
102 103 104
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Print options for
// the sheet. Printer-specific settings are stored separately in the Printer
// Settings part.
xurime's avatar
xurime 已提交
105
type xlsxPrintOptions struct {
106 107 108 109 110
	GridLines          bool `xml:"gridLines,attr,omitempty"`
	GridLinesSet       bool `xml:"gridLinesSet,attr,omitempty"`
	Headings           bool `xml:"headings,attr,omitempty"`
	HorizontalCentered bool `xml:"horizontalCentered,attr,omitempty"`
	VerticalCentered   bool `xml:"verticalCentered,attr,omitempty"`
xurime's avatar
xurime 已提交
111 112 113
}

// xlsxPageMargins directly maps the pageMargins element in the namespace
114 115
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page margins for
// a sheet or a custom sheet view.
xurime's avatar
xurime 已提交
116
type xlsxPageMargins struct {
117 118 119
	Bottom float64 `xml:"bottom,attr"`
	Footer float64 `xml:"footer,attr"`
	Header float64 `xml:"header,attr"`
xurime's avatar
xurime 已提交
120 121 122 123 124 125
	Left   float64 `xml:"left,attr"`
	Right  float64 `xml:"right,attr"`
	Top    float64 `xml:"top,attr"`
}

// xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
126 127
// http://schemas.openxmlformats.org/spreadsheetml/2006/main. This element
// specifies the sheet formatting properties.
xurime's avatar
xurime 已提交
128
type xlsxSheetFormatPr struct {
129
	BaseColWidth     uint8   `xml:"baseColWidth,attr,omitempty"`
xurime's avatar
xurime 已提交
130 131
	DefaultColWidth  float64 `xml:"defaultColWidth,attr,omitempty"`
	DefaultRowHeight float64 `xml:"defaultRowHeight,attr"`
xurime's avatar
xurime 已提交
132 133
	CustomHeight     bool    `xml:"customHeight,attr,omitempty"`
	ZeroHeight       bool    `xml:"zeroHeight,attr,omitempty"`
134
	ThickTop         bool    `xml:"thickTop,attr,omitempty"`
xurime's avatar
xurime 已提交
135
	ThickBottom      bool    `xml:"thickBottom,attr,omitempty"`
xurime's avatar
xurime 已提交
136
	OutlineLevelRow  uint8   `xml:"outlineLevelRow,attr,omitempty"`
xurime's avatar
xurime 已提交
137
	OutlineLevelCol  uint8   `xml:"outlineLevelCol,attr,omitempty"`
xurime's avatar
xurime 已提交
138 139 140
}

// xlsxSheetViews directly maps the sheetViews element in the namespace
141 142
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet views
// collection.
xurime's avatar
xurime 已提交
143 144 145 146 147
type xlsxSheetViews struct {
	SheetView []xlsxSheetView `xml:"sheetView"`
}

// xlsxSheetView directly maps the sheetView element in the namespace
148 149 150 151 152 153 154 155
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need. A single sheet
// view definition. When more than one sheet view is defined in the file, it
// means that when opening the workbook, each sheet view corresponds to a
// separate window within the spreadsheet application, where each window is
// showing the particular sheet containing the same workbookViewId value, the
// last sheetView definition is loaded, and the others are discarded. When
// multiple windows are viewing the same sheet, multiple sheetView elements
156
// (with corresponding workbookView entries) are saved.
157
// See https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetview.aspx
xurime's avatar
xurime 已提交
158
type xlsxSheetView struct {
159 160
	WindowProtection         bool             `xml:"windowProtection,attr,omitempty"`
	ShowFormulas             bool             `xml:"showFormulas,attr,omitempty"`
161 162
	ShowGridLines            *bool            `xml:"showGridLines,attr"`
	ShowRowColHeaders        *bool            `xml:"showRowColHeaders,attr"`
163 164 165 166 167
	ShowZeros                bool             `xml:"showZeros,attr,omitempty"`
	RightToLeft              bool             `xml:"rightToLeft,attr,omitempty"`
	TabSelected              bool             `xml:"tabSelected,attr,omitempty"`
	ShowWhiteSpace           *bool            `xml:"showWhiteSpace,attr"`
	ShowOutlineSymbols       bool             `xml:"showOutlineSymbols,attr,omitempty"`
168
	DefaultGridColor         *bool            `xml:"defaultGridColor,attr"`
169 170 171 172 173 174 175 176 177 178
	View                     string           `xml:"view,attr,omitempty"`
	TopLeftCell              string           `xml:"topLeftCell,attr,omitempty"`
	ColorID                  int              `xml:"colorId,attr,omitempty"`
	ZoomScale                float64          `xml:"zoomScale,attr,omitempty"`
	ZoomScaleNormal          float64          `xml:"zoomScaleNormal,attr,omitempty"`
	ZoomScalePageLayoutView  float64          `xml:"zoomScalePageLayoutView,attr,omitempty"`
	ZoomScaleSheetLayoutView float64          `xml:"zoomScaleSheetLayoutView,attr,omitempty"`
	WorkbookViewID           int              `xml:"workbookViewId,attr"`
	Pane                     *xlsxPane        `xml:"pane,omitempty"`
	Selection                []*xlsxSelection `xml:"selection"`
xurime's avatar
xurime 已提交
179 180 181
}

// xlsxSelection directly maps the selection element in the namespace
182 183
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet view
// selection.
xurime's avatar
xurime 已提交
184
type xlsxSelection struct {
185
	ActiveCell   string `xml:"activeCell,attr,omitempty"`
xurime's avatar
xurime 已提交
186
	ActiveCellID *int   `xml:"activeCellId,attr"`
187
	Pane         string `xml:"pane,attr,omitempty"`
188
	SQRef        string `xml:"sqref,attr,omitempty"`
xurime's avatar
xurime 已提交
189 190
}

191
// xlsxSelection directly maps the selection element. Worksheet view pane.
xurime's avatar
xurime 已提交
192 193 194
type xlsxPane struct {
	ActivePane  string  `xml:"activePane,attr,omitempty"`
	State       string  `xml:"state,attr,omitempty"` // Either "split" or "frozen"
195 196 197
	TopLeftCell string  `xml:"topLeftCell,attr,omitempty"`
	XSplit      float64 `xml:"xSplit,attr,omitempty"`
	YSplit      float64 `xml:"ySplit,attr,omitempty"`
xurime's avatar
xurime 已提交
198 199 200
}

// xlsxSheetPr directly maps the sheetPr element in the namespace
201 202
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Sheet-level
// properties.
xurime's avatar
xurime 已提交
203
type xlsxSheetPr struct {
204 205
	XMLName                           xml.Name         `xml:"sheetPr"`
	CodeName                          string           `xml:"codeName,attr,omitempty"`
206
	EnableFormatConditionsCalculation *bool            `xml:"enableFormatConditionsCalculation,attr"`
207
	FilterMode                        bool             `xml:"filterMode,attr,omitempty"`
O
Olivier Mengué 已提交
208
	Published                         *bool            `xml:"published,attr"`
209 210 211 212 213
	SyncHorizontal                    bool             `xml:"syncHorizontal,attr,omitempty"`
	SyncVertical                      bool             `xml:"syncVertical,attr,omitempty"`
	TransitionEntry                   bool             `xml:"transitionEntry,attr,omitempty"`
	TabColor                          *xlsxTabColor    `xml:"tabColor,omitempty"`
	PageSetUpPr                       *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
H
Harris 已提交
214 215 216 217 218 219 220
	OutlinePr                         *xlsxOutlinePr   `xml:"outlinePr,omitempty"`
}

// xlsxOutlinePr maps to the outlinePr element
// SummaryBelow allows you to adjust the direction of grouper controls
type xlsxOutlinePr struct {
	SummaryBelow bool `xml:"summaryBelow,attr"`
xurime's avatar
xurime 已提交
221 222 223
}

// xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
224 225
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
// properties of the worksheet.
xurime's avatar
xurime 已提交
226
type xlsxPageSetUpPr struct {
227 228
	AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"`
	FitToPage      bool `xml:"fitToPage,attr,omitempty"` // Flag indicating whether the Fit to Page print option is enabled.
229 230
}

231 232
// xlsxTabColor directly maps the tabColor element in the namespace currently I
// have not checked it for completeness - it does as much as I need.
233
type xlsxTabColor struct {
234 235
	Theme int     `xml:"theme,attr,omitempty"`
	Tint  float64 `xml:"tint,attr,omitempty"`
xurime's avatar
xurime 已提交
236 237 238
}

// xlsxCols directly maps the cols element in the namespace
239 240
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
241 242 243 244
type xlsxCols struct {
	Col []xlsxCol `xml:"col"`
}

245 246
// xlsxCol directly maps the col (Column Width & Formatting). Defines column
// width and column formatting for one or more columns of the worksheet.
xurime's avatar
xurime 已提交
247
type xlsxCol struct {
248
	BestFit      bool    `xml:"bestFit,attr,omitempty"`
xurime's avatar
xurime 已提交
249
	Collapsed    bool    `xml:"collapsed,attr"`
250
	CustomWidth  bool    `xml:"customWidth,attr,omitempty"`
xurime's avatar
xurime 已提交
251 252 253
	Hidden       bool    `xml:"hidden,attr"`
	Max          int     `xml:"max,attr"`
	Min          int     `xml:"min,attr"`
254 255
	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
	Phonetic     bool    `xml:"phonetic,attr,omitempty"`
xurime's avatar
xurime 已提交
256 257 258 259 260
	Style        int     `xml:"style,attr"`
	Width        float64 `xml:"width,attr"`
}

// xlsxDimension directly maps the dimension element in the namespace
261 262 263 264 265 266
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element
// specifies the used range of the worksheet. It specifies the row and column
// bounds of used cells in the worksheet. This is optional and is not required.
// Used cells include cells with formulas, text content, and cell formatting.
// When an entire column is formatted, only the first cell in that column is
// considered used.
xurime's avatar
xurime 已提交
267 268 269 270 271
type xlsxDimension struct {
	Ref string `xml:"ref,attr"`
}

// xlsxSheetData directly maps the sheetData element in the namespace
272 273
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
274 275 276 277 278
type xlsxSheetData struct {
	XMLName xml.Name  `xml:"sheetData"`
	Row     []xlsxRow `xml:"row"`
}

279
// xlsxRow directly maps the row element. The element expresses information
280 281
// about an entire row of a worksheet, and contains all cell definitions for a
// particular row in the worksheet.
xurime's avatar
xurime 已提交
282
type xlsxRow struct {
283 284 285
	Collapsed    bool    `xml:"collapsed,attr,omitempty"`
	CustomFormat bool    `xml:"customFormat,attr,omitempty"`
	CustomHeight bool    `xml:"customHeight,attr,omitempty"`
xurime's avatar
xurime 已提交
286
	Hidden       bool    `xml:"hidden,attr,omitempty"`
287
	Ht           float64 `xml:"ht,attr,omitempty"`
xurime's avatar
xurime 已提交
288
	OutlineLevel uint8   `xml:"outlineLevel,attr,omitempty"`
289 290 291 292 293 294 295
	Ph           bool    `xml:"ph,attr,omitempty"`
	R            int     `xml:"r,attr,omitempty"`
	S            int     `xml:"s,attr,omitempty"`
	Spans        string  `xml:"spans,attr,omitempty"`
	ThickBot     bool    `xml:"thickBot,attr,omitempty"`
	ThickTop     bool    `xml:"thickTop,attr,omitempty"`
	C            []xlsxC `xml:"c"`
xurime's avatar
xurime 已提交
296 297
}

298
// xlsxMergeCell directly maps the mergeCell element. A single merged cell.
xurime's avatar
xurime 已提交
299
type xlsxMergeCell struct {
300
	Ref string `xml:"ref,attr,omitempty"`
xurime's avatar
xurime 已提交
301 302
}

303 304
// xlsxMergeCells directly maps the mergeCells element. This collection
// expresses all the merged cells in the sheet.
xurime's avatar
xurime 已提交
305
type xlsxMergeCells struct {
306 307
	Count int              `xml:"count,attr,omitempty"`
	Cells []*xlsxMergeCell `xml:"mergeCell,omitempty"`
xurime's avatar
xurime 已提交
308 309
}

310 311 312
// xlsxDataValidations expresses all data validation information for cells in a
// sheet which have data validation features applied.
type xlsxDataValidations struct {
Reage--'s avatar
Reage-- 已提交
313 314 315 316
	Count          int               `xml:"count,attr,omitempty"`
	DisablePrompts bool              `xml:"disablePrompts,attr,omitempty"`
	XWindow        int               `xml:"xWindow,attr,omitempty"`
	YWindow        int               `xml:"yWindow,attr,omitempty"`
317
	DataValidation []*DataValidation `xml:"dataValidation"`
Reage--'s avatar
Reage-- 已提交
318 319
}

xurime's avatar
xurime 已提交
320 321
// DataValidation directly maps the a single item of data validation defined
// on a range of the worksheet.
Reage--'s avatar
Reage-- 已提交
322
type DataValidation struct {
xurime's avatar
xurime 已提交
323 324 325 326 327
	AllowBlank       bool    `xml:"allowBlank,attr"`
	Error            *string `xml:"error,attr"`
	ErrorStyle       *string `xml:"errorStyle,attr"`
	ErrorTitle       *string `xml:"errorTitle,attr"`
	Operator         string  `xml:"operator,attr"`
Reage--'s avatar
Reage-- 已提交
328
	Prompt           *string `xml:"prompt,attr"`
xurime's avatar
xurime 已提交
329 330 331 332 333 334 335 336
	PromptTitle      *string `xml:"promptTitle"`
	ShowDropDown     bool    `xml:"showDropDown,attr"`
	ShowErrorMessage bool    `xml:"showErrorMessage,attr"`
	ShowInputMessage bool    `xml:"showInputMessage,attr"`
	Sqref            string  `xml:"sqref,attr"`
	Type             string  `xml:"type,attr"`
	Formula1         string  `xml:"formula1"`
	Formula2         string  `xml:"formula2"`
337 338
}

xurime's avatar
xurime 已提交
339
// xlsxC directly maps the c element in the namespace
340 341
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
342 343 344 345 346 347 348 349 350 351 352 353 354
//
// This simple type is restricted to the values listed in the following table:
//
//      Enumeration Value         | Description
//     ---------------------------+---------------------------------
//      b (Boolean)               | Cell containing a boolean.
//      d (Date)                  | Cell contains a date in the ISO 8601 format.
//      e (Error)                 | Cell containing an error.
//      inlineStr (Inline String) | Cell containing an (inline) rich string, i.e., one not in the shared string table. If this cell type is used, then the cell value is in the is element rather than the v element in the cell (c element).
//      n (Number)                | Cell containing a number.
//      s (Shared String)         | Cell containing a shared string.
//      str (String)              | Cell containing a formula string.
//
xurime's avatar
xurime 已提交
355 356 357 358
type xlsxC struct {
	R string `xml:"r,attr"`           // Cell ID, e.g. A1
	S int    `xml:"s,attr,omitempty"` // Style reference.
	// Str string `xml:"str,attr,omitempty"` // Style reference.
359 360 361
	T        string   `xml:"t,attr,omitempty"` // Type.
	F        *xlsxF   `xml:"f,omitempty"`      // Formula
	V        string   `xml:"v,omitempty"`      // Value
362
	IS       *xlsxIS  `xml:"is"`
363
	XMLSpace xml.Attr `xml:"space,attr,omitempty"`
xurime's avatar
xurime 已提交
364 365
}

366 367 368 369 370 371 372 373
// xlsxIS directly maps the t element. Cell containing an (inline) rich
// string, i.e., one not in the shared string table. If this cell type is
// used, then the cell value is in the is element rather than the v element in
// the cell (c element).
type xlsxIS struct {
	T string `xml:"t"`
}

xurime's avatar
xurime 已提交
374
// xlsxF directly maps the f element in the namespace
375 376
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
xurime's avatar
xurime 已提交
377 378 379 380
type xlsxF struct {
	Content string `xml:",chardata"`
	T       string `xml:"t,attr,omitempty"`   // Formula type
	Ref     string `xml:"ref,attr,omitempty"` // Shared formula ref
381
	Si      string `xml:"si,attr,omitempty"`  // Shared formula index
xurime's avatar
xurime 已提交
382
}
383

384 385
// xlsxSheetProtection collection expresses the sheet protection options to
// enforce when the sheet is protected.
386
type xlsxSheetProtection struct {
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	AlgorithmName       string `xml:"algorithmName,attr,omitempty"`
	AutoFilter          bool   `xml:"autoFilter,attr,omitempty"`
	DeleteColumns       bool   `xml:"deleteColumns,attr,omitempty"`
	DeleteRows          bool   `xml:"deleteRows,attr,omitempty"`
	FormatCells         bool   `xml:"formatCells,attr,omitempty"`
	FormatColumns       bool   `xml:"formatColumns,attr,omitempty"`
	FormatRows          bool   `xml:"formatRows,attr,omitempty"`
	HashValue           string `xml:"hashValue,attr,omitempty"`
	InsertColumns       bool   `xml:"insertColumns,attr,omitempty"`
	InsertHyperlinks    bool   `xml:"insertHyperlinks,attr,omitempty"`
	InsertRows          bool   `xml:"insertRows,attr,omitempty"`
	Objects             bool   `xml:"objects,attr,omitempty"`
	Password            string `xml:"password,attr,omitempty"`
	PivotTables         bool   `xml:"pivotTables,attr,omitempty"`
	SaltValue           string `xml:"saltValue,attr,omitempty"`
	Scenarios           bool   `xml:"scenarios,attr,omitempty"`
	SelectLockedCells   bool   `xml:"selectLockedCells,attr,omitempty"`
	SelectUnlockedCells bool   `xml:"selectUnlockedCells,attr,omitempty"`
	Sheet               bool   `xml:"sheet,attr,omitempty"`
	Sort                bool   `xml:"sort,attr,omitempty"`
	SpinCount           int    `xml:"spinCount,attr,omitempty"`
408 409
}

410 411 412 413 414 415 416 417 418
// xlsxPhoneticPr (Phonetic Properties) represents a collection of phonetic
// properties that affect the display of phonetic text for this String Item
// (si). Phonetic text is used to give hints as to the pronunciation of an East
// Asian language, and the hints are displayed as text within the spreadsheet
// cells across the top portion of the cell. Since the phonetic hints are text,
// every phonetic hint is expressed as a phonetic run (rPh), and these
// properties specify how to display that phonetic run.
type xlsxPhoneticPr struct {
	Alignment string `xml:"alignment,attr,omitempty"`
419
	FontID    *int   `xml:"fontId,attr"`
420 421 422
	Type      string `xml:"type,attr,omitempty"`
}

423 424 425 426
// A Conditional Format is a format, such as cell shading or font color, that a
// spreadsheet application can automatically apply to cells if a specified
// condition is true. This collection expresses conditional formatting rules
// applied to a particular cell or range.
427
type xlsxConditionalFormatting struct {
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
	SQRef  string        `xml:"sqref,attr,omitempty"`
	CfRule []*xlsxCfRule `xml:"cfRule"`
}

// xlsxCfRule (Conditional Formatting Rule) represents a description of a
// conditional formatting rule.
type xlsxCfRule struct {
	AboveAverage *bool           `xml:"aboveAverage,attr"`
	Bottom       bool            `xml:"bottom,attr,omitempty"`
	DxfID        *int            `xml:"dxfId,attr"`
	EqualAverage bool            `xml:"equalAverage,attr,omitempty"`
	Operator     string          `xml:"operator,attr,omitempty"`
	Percent      bool            `xml:"percent,attr,omitempty"`
	Priority     int             `xml:"priority,attr,omitempty"`
	Rank         int             `xml:"rank,attr,omitempty"`
	StdDev       int             `xml:"stdDev,attr,omitempty"`
	StopIfTrue   bool            `xml:"stopIfTrue,attr,omitempty"`
	Text         string          `xml:"text,attr,omitempty"`
	TimePeriod   string          `xml:"timePeriod,attr,omitempty"`
	Type         string          `xml:"type,attr,omitempty"`
	Formula      []string        `xml:"formula,omitempty"`
	ColorScale   *xlsxColorScale `xml:"colorScale"`
	DataBar      *xlsxDataBar    `xml:"dataBar"`
	IconSet      *xlsxIconSet    `xml:"iconSet"`
	ExtLst       *xlsxExtLst     `xml:"extLst"`
}

// xlsxColorScale (Color Scale) describes a gradated color scale in this
// conditional formatting rule.
type xlsxColorScale struct {
	Cfvo  []*xlsxCfvo  `xml:"cfvo"`
	Color []*xlsxColor `xml:"color"`
}

// dataBar (Data Bar) describes a data bar conditional formatting rule.
type xlsxDataBar struct {
	MaxLength int          `xml:"maxLength,attr,omitempty"`
	MinLength int          `xml:"minLength,attr,omitempty"`
	ShowValue bool         `xml:"showValue,attr,omitempty"`
	Cfvo      []*xlsxCfvo  `xml:"cfvo"`
	Color     []*xlsxColor `xml:"color"`
}

// xlsxIconSet (Icon Set) describes an icon set conditional formatting rule.
type xlsxIconSet struct {
	Cfvo      []*xlsxCfvo `xml:"cfvo"`
	IconSet   string      `xml:"iconSet,attr,omitempty"`
	ShowValue bool        `xml:"showValue,attr,omitempty"`
	Percent   bool        `xml:"percent,attr,omitempty"`
	Reverse   bool        `xml:"reverse,attr,omitempty"`
}

// cfvo (Conditional Format Value Object) describes the values of the
// interpolation points in a gradient scale.
type xlsxCfvo struct {
	Gte    bool        `xml:"gte,attr,omitempty"`
	Type   string      `xml:"type,attr,omitempty"`
485
	Val    string      `xml:"val,attr"`
486
	ExtLst *xlsxExtLst `xml:"extLst"`
487 488
}

489
// xlsxHyperlinks directly maps the hyperlinks element in the namespace
490 491 492
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - A hyperlink can
// be stored in a package as a relationship. Hyperlinks shall be identified by
// containing a target which specifies the destination of the given hyperlink.
493 494 495 496 497 498 499 500 501 502 503 504
type xlsxHyperlinks struct {
	Hyperlink []xlsxHyperlink `xml:"hyperlink"`
}

// xlsxHyperlink directly maps the hyperlink element in the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main
type xlsxHyperlink struct {
	Ref      string `xml:"ref,attr"`
	Location string `xml:"location,attr,omitempty"`
	Display  string `xml:"display,attr,omitempty"`
	RID      string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
}
505 506

// xlsxTableParts directly maps the tableParts element in the namespace
507 508 509 510 511 512 513 514 515 516
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - The table element
// has several attributes applied to identify the table and the data range it
// covers. The table id attribute needs to be unique across all table parts, the
// same goes for the name and displayName. The displayName has the further
// restriction that it must be unique across all defined names in the workbook.
// Later on we will see that you can define names for many elements, such as
// cells or formulas. The name value is used for the object model in Microsoft
// Office Excel. The displayName is used for references in formulas. The ref
// attribute is used to identify the cell range that the table covers. This
// includes not only the table data, but also the table header containing column
517 518
// names.
// To add columns to your table you add new tableColumn elements to the
519 520 521 522 523 524 525 526 527 528
// tableColumns container. Similar to the shared string table the collection
// keeps a count attribute identifying the number of columns. Besides the table
// definition in the table part there is also the need to identify which tables
// are displayed in the worksheet. The worksheet part has a separate element
// tableParts to store this information. Each table part is referenced through
// the relationship ID and again a count of the number of table parts is
// maintained. The following markup sample is taken from the documents
// accompanying this book. The sheet data element has been removed to reduce the
// size of the sample. To reference the table, just add the tableParts element,
// of course after having created and stored the table part. For example:
529 530 531 532 533 534 535 536 537
//
//    <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
//        ...
//        <tableParts count="1">
// 		      <tablePart r:id="rId1" />
//        </tableParts>
//    </worksheet>
//
type xlsxTableParts struct {
538 539
	Count      int              `xml:"count,attr,omitempty"`
	TableParts []*xlsxTablePart `xml:"tablePart"`
540 541 542 543 544 545 546 547 548
}

// xlsxTablePart directly maps the tablePart element in the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main
type xlsxTablePart struct {
	RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
}

// xlsxPicture directly maps the picture element in the namespace
549 550
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet
// image. For example:
551 552 553 554
//
//    <picture r:id="rId1"/>
//
type xlsxPicture struct {
555
	RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
556
}
xurime's avatar
xurime 已提交
557 558

// xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace
559 560 561 562 563 564 565 566
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - A comment is a
// rich text note that is attached to, and associated with, a cell, separate
// from other cell content. Comment content is stored separate from the cell,
// and is displayed in a drawing object (like a text box) that is separate from,
// but associated with, a cell. Comments are used as reminders, such as noting
// how a complex formula works, or to provide feedback to other users. Comments
// can also be used to explain assumptions made in a formula or to call out
// something special about the cell.
xurime's avatar
xurime 已提交
567 568 569
type xlsxLegacyDrawing struct {
	RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
}
xurime's avatar
xurime 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584

// formatPanes directly maps the settings of the panes.
type formatPanes struct {
	Freeze      bool   `json:"freeze"`
	Split       bool   `json:"split"`
	XSplit      int    `json:"x_split"`
	YSplit      int    `json:"y_split"`
	TopLeftCell string `json:"top_left_cell"`
	ActivePane  string `json:"active_pane"`
	Panes       []struct {
		SQRef      string `json:"sqref"`
		ActiveCell string `json:"active_cell"`
		Pane       string `json:"pane"`
	} `json:"panes"`
}
585

xurime's avatar
xurime 已提交
586
// formatConditional directly maps the conditional format settings of the cells.
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
type formatConditional struct {
	Type         string `json:"type"`
	AboveAverage bool   `json:"above_average"`
	Percent      bool   `json:"percent"`
	Format       int    `json:"format"`
	Criteria     string `json:"criteria"`
	Value        string `json:"value,omitempty"`
	Minimum      string `json:"minimum,omitempty"`
	Maximum      string `json:"maximum,omitempty"`
	MinType      string `json:"min_type,omitempty"`
	MidType      string `json:"mid_type,omitempty"`
	MaxType      string `json:"max_type,omitempty"`
	MinValue     string `json:"min_value,omitempty"`
	MidValue     string `json:"mid_value,omitempty"`
	MaxValue     string `json:"max_value,omitempty"`
	MinColor     string `json:"min_color,omitempty"`
	MidColor     string `json:"mid_color,omitempty"`
	MaxColor     string `json:"max_color,omitempty"`
	MinLength    string `json:"min_length,omitempty"`
	MaxLength    string `json:"max_length,omitempty"`
	MultiRange   string `json:"multi_range,omitempty"`
	BarColor     string `json:"bar_color,omitempty"`
}
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

// FormatSheetProtection directly maps the settings of worksheet protection.
type FormatSheetProtection struct {
	AutoFilter          bool
	DeleteColumns       bool
	DeleteRows          bool
	EditObjects         bool
	EditScenarios       bool
	FormatCells         bool
	FormatColumns       bool
	FormatRows          bool
	InsertColumns       bool
	InsertHyperlinks    bool
	InsertRows          bool
	Password            string
	PivotTables         bool
	SelectLockedCells   bool
	SelectUnlockedCells bool
	Sort                bool
}