xmlWorksheet.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. // Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.10 or later.
  9. package excelize
  10. import "encoding/xml"
  11. // xlsxWorksheet directly maps the worksheet element in the namespace
  12. // http://schemas.openxmlformats.org/spreadsheetml/2006/main.
  13. type xlsxWorksheet struct {
  14. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
  15. SheetPr *xlsxSheetPr `xml:"sheetPr"`
  16. Dimension *xlsxDimension `xml:"dimension"`
  17. SheetViews *xlsxSheetViews `xml:"sheetViews"`
  18. SheetFormatPr *xlsxSheetFormatPr `xml:"sheetFormatPr"`
  19. Cols *xlsxCols `xml:"cols"`
  20. SheetData xlsxSheetData `xml:"sheetData"`
  21. SheetCalcPr *xlsxInnerXML `xml:"sheetCalcPr"`
  22. SheetProtection *xlsxSheetProtection `xml:"sheetProtection"`
  23. ProtectedRanges *xlsxInnerXML `xml:"protectedRanges"`
  24. Scenarios *xlsxInnerXML `xml:"scenarios"`
  25. AutoFilter *xlsxAutoFilter `xml:"autoFilter"`
  26. SortState *xlsxSortState `xml:"sortState"`
  27. DataConsolidate *xlsxInnerXML `xml:"dataConsolidate"`
  28. CustomSheetViews *xlsxCustomSheetViews `xml:"customSheetViews"`
  29. MergeCells *xlsxMergeCells `xml:"mergeCells"`
  30. PhoneticPr *xlsxPhoneticPr `xml:"phoneticPr"`
  31. ConditionalFormatting []*xlsxConditionalFormatting `xml:"conditionalFormatting"`
  32. DataValidations *xlsxDataValidations `xml:"dataValidations"`
  33. Hyperlinks *xlsxHyperlinks `xml:"hyperlinks"`
  34. PrintOptions *xlsxPrintOptions `xml:"printOptions"`
  35. PageMargins *xlsxPageMargins `xml:"pageMargins"`
  36. PageSetUp *xlsxPageSetUp `xml:"pageSetup"`
  37. HeaderFooter *xlsxHeaderFooter `xml:"headerFooter"`
  38. RowBreaks *xlsxBreaks `xml:"rowBreaks"`
  39. ColBreaks *xlsxBreaks `xml:"colBreaks"`
  40. CustomProperties *xlsxInnerXML `xml:"customProperties"`
  41. CellWatches *xlsxInnerXML `xml:"cellWatches"`
  42. IgnoredErrors *xlsxInnerXML `xml:"ignoredErrors"`
  43. SmartTags *xlsxInnerXML `xml:"smartTags"`
  44. Drawing *xlsxDrawing `xml:"drawing"`
  45. LegacyDrawing *xlsxLegacyDrawing `xml:"legacyDrawing"`
  46. LegacyDrawingHF *xlsxLegacyDrawingHF `xml:"legacyDrawingHF"`
  47. DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
  48. Picture *xlsxPicture `xml:"picture"`
  49. OleObjects *xlsxInnerXML `xml:"oleObjects"`
  50. Controls *xlsxInnerXML `xml:"controls"`
  51. WebPublishItems *xlsxInnerXML `xml:"webPublishItems"`
  52. TableParts *xlsxTableParts `xml:"tableParts"`
  53. ExtLst *xlsxExtLst `xml:"extLst"`
  54. }
  55. // xlsxDrawing change r:id to rid in the namespace.
  56. type xlsxDrawing struct {
  57. XMLName xml.Name `xml:"drawing"`
  58. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  59. }
  60. // xlsxHeaderFooter directly maps the headerFooter element in the namespace
  61. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - When printed or
  62. // viewed in page layout view (§18.18.69), each page of a worksheet can have a
  63. // page header, a page footer, or both. The headers and footers on odd-numbered
  64. // pages can differ from those on even-numbered pages, and the headers and
  65. // footers on the first page can differ from those on odd- and even-numbered
  66. // pages. In the latter case, the first page is not considered an odd page.
  67. type xlsxHeaderFooter struct {
  68. XMLName xml.Name `xml:"headerFooter"`
  69. AlignWithMargins bool `xml:"alignWithMargins,attr,omitempty"`
  70. DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
  71. DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
  72. ScaleWithDoc bool `xml:"scaleWithDoc,attr,omitempty"`
  73. OddHeader string `xml:"oddHeader,omitempty"`
  74. OddFooter string `xml:"oddFooter,omitempty"`
  75. EvenHeader string `xml:"evenHeader,omitempty"`
  76. EvenFooter string `xml:"evenFooter,omitempty"`
  77. FirstFooter string `xml:"firstFooter,omitempty"`
  78. FirstHeader string `xml:"firstHeader,omitempty"`
  79. DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
  80. }
  81. // xlsxDrawingHF (Drawing Reference in Header Footer) specifies the usage of
  82. // drawing objects to be rendered in the headers and footers of the sheet. It
  83. // specifies an explicit relationship to the part containing the DrawingML
  84. // shapes used in the headers and footers. It also indicates where in the
  85. // headers and footers each shape belongs. One drawing object can appear in
  86. // each of the left section, center section and right section of a header and
  87. // a footer.
  88. type xlsxDrawingHF struct {
  89. Content string `xml:",innerxml"`
  90. }
  91. // xlsxPageSetUp directly maps the pageSetup element in the namespace
  92. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
  93. // settings for the worksheet.
  94. type xlsxPageSetUp struct {
  95. XMLName xml.Name `xml:"pageSetup"`
  96. BlackAndWhite bool `xml:"blackAndWhite,attr,omitempty"`
  97. CellComments string `xml:"cellComments,attr,omitempty"`
  98. Copies int `xml:"copies,attr,omitempty"`
  99. Draft bool `xml:"draft,attr,omitempty"`
  100. Errors string `xml:"errors,attr,omitempty"`
  101. FirstPageNumber int `xml:"firstPageNumber,attr,omitempty"`
  102. FitToHeight int `xml:"fitToHeight,attr,omitempty"`
  103. FitToWidth int `xml:"fitToWidth,attr,omitempty"`
  104. HorizontalDPI int `xml:"horizontalDpi,attr,omitempty"`
  105. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  106. Orientation string `xml:"orientation,attr,omitempty"`
  107. PageOrder string `xml:"pageOrder,attr,omitempty"`
  108. PaperHeight string `xml:"paperHeight,attr,omitempty"`
  109. PaperSize int `xml:"paperSize,attr,omitempty"`
  110. PaperWidth string `xml:"paperWidth,attr,omitempty"`
  111. Scale int `xml:"scale,attr,omitempty"`
  112. UseFirstPageNumber bool `xml:"useFirstPageNumber,attr,omitempty"`
  113. UsePrinterDefaults bool `xml:"usePrinterDefaults,attr,omitempty"`
  114. VerticalDPI int `xml:"verticalDpi,attr,omitempty"`
  115. }
  116. // xlsxPrintOptions directly maps the printOptions element in the namespace
  117. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Print options for
  118. // the sheet. Printer-specific settings are stored separately in the Printer
  119. // Settings part.
  120. type xlsxPrintOptions struct {
  121. XMLName xml.Name `xml:"printOptions"`
  122. GridLines bool `xml:"gridLines,attr,omitempty"`
  123. GridLinesSet bool `xml:"gridLinesSet,attr,omitempty"`
  124. Headings bool `xml:"headings,attr,omitempty"`
  125. HorizontalCentered bool `xml:"horizontalCentered,attr,omitempty"`
  126. VerticalCentered bool `xml:"verticalCentered,attr,omitempty"`
  127. }
  128. // xlsxPageMargins directly maps the pageMargins element in the namespace
  129. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page margins for
  130. // a sheet or a custom sheet view.
  131. type xlsxPageMargins struct {
  132. XMLName xml.Name `xml:"pageMargins"`
  133. Bottom float64 `xml:"bottom,attr"`
  134. Footer float64 `xml:"footer,attr"`
  135. Header float64 `xml:"header,attr"`
  136. Left float64 `xml:"left,attr"`
  137. Right float64 `xml:"right,attr"`
  138. Top float64 `xml:"top,attr"`
  139. }
  140. // xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
  141. // http://schemas.openxmlformats.org/spreadsheetml/2006/main. This element
  142. // specifies the sheet formatting properties.
  143. type xlsxSheetFormatPr struct {
  144. XMLName xml.Name `xml:"sheetFormatPr"`
  145. BaseColWidth uint8 `xml:"baseColWidth,attr,omitempty"`
  146. DefaultColWidth float64 `xml:"defaultColWidth,attr,omitempty"`
  147. DefaultRowHeight float64 `xml:"defaultRowHeight,attr"`
  148. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  149. ZeroHeight bool `xml:"zeroHeight,attr,omitempty"`
  150. ThickTop bool `xml:"thickTop,attr,omitempty"`
  151. ThickBottom bool `xml:"thickBottom,attr,omitempty"`
  152. OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"`
  153. OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
  154. }
  155. // xlsxSheetViews directly maps the sheetViews element in the namespace
  156. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet views
  157. // collection.
  158. type xlsxSheetViews struct {
  159. XMLName xml.Name `xml:"sheetViews"`
  160. SheetView []xlsxSheetView `xml:"sheetView"`
  161. }
  162. // xlsxSheetView directly maps the sheetView element in the namespace
  163. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  164. // not checked it for completeness - it does as much as I need. A single sheet
  165. // view definition. When more than one sheet view is defined in the file, it
  166. // means that when opening the workbook, each sheet view corresponds to a
  167. // separate window within the spreadsheet application, where each window is
  168. // showing the particular sheet containing the same workbookViewId value, the
  169. // last sheetView definition is loaded, and the others are discarded. When
  170. // multiple windows are viewing the same sheet, multiple sheetView elements
  171. // (with corresponding workbookView entries) are saved.
  172. // See https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetview
  173. type xlsxSheetView struct {
  174. WindowProtection bool `xml:"windowProtection,attr,omitempty"`
  175. ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
  176. ShowGridLines *bool `xml:"showGridLines,attr"`
  177. ShowRowColHeaders *bool `xml:"showRowColHeaders,attr"`
  178. ShowZeros *bool `xml:"showZeros,attr,omitempty"`
  179. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  180. TabSelected bool `xml:"tabSelected,attr,omitempty"`
  181. ShowWhiteSpace *bool `xml:"showWhiteSpace,attr"`
  182. ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr,omitempty"`
  183. DefaultGridColor *bool `xml:"defaultGridColor,attr"`
  184. View string `xml:"view,attr,omitempty"`
  185. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  186. ColorID int `xml:"colorId,attr,omitempty"`
  187. ZoomScale float64 `xml:"zoomScale,attr,omitempty"`
  188. ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"`
  189. ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"`
  190. ZoomScaleSheetLayoutView float64 `xml:"zoomScaleSheetLayoutView,attr,omitempty"`
  191. WorkbookViewID int `xml:"workbookViewId,attr"`
  192. Pane *xlsxPane `xml:"pane,omitempty"`
  193. Selection []*xlsxSelection `xml:"selection"`
  194. }
  195. // xlsxSelection directly maps the selection element in the namespace
  196. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet view
  197. // selection.
  198. type xlsxSelection struct {
  199. ActiveCell string `xml:"activeCell,attr,omitempty"`
  200. ActiveCellID *int `xml:"activeCellId,attr"`
  201. Pane string `xml:"pane,attr,omitempty"`
  202. SQRef string `xml:"sqref,attr,omitempty"`
  203. }
  204. // xlsxSelection directly maps the selection element. Worksheet view pane.
  205. type xlsxPane struct {
  206. ActivePane string `xml:"activePane,attr,omitempty"`
  207. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  208. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  209. XSplit float64 `xml:"xSplit,attr,omitempty"`
  210. YSplit float64 `xml:"ySplit,attr,omitempty"`
  211. }
  212. // xlsxSheetPr directly maps the sheetPr element in the namespace
  213. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Sheet-level
  214. // properties.
  215. type xlsxSheetPr struct {
  216. XMLName xml.Name `xml:"sheetPr"`
  217. SyncHorizontal bool `xml:"syncHorizontal,attr,omitempty"`
  218. SyncVertical bool `xml:"syncVertical,attr,omitempty"`
  219. SyncRef string `xml:"syncRef,attr,omitempty"`
  220. TransitionEvaluation bool `xml:"transitionEvaluation,attr,omitempty"`
  221. Published *bool `xml:"published,attr"`
  222. CodeName string `xml:"codeName,attr,omitempty"`
  223. FilterMode bool `xml:"filterMode,attr,omitempty"`
  224. EnableFormatConditionsCalculation *bool `xml:"enableFormatConditionsCalculation,attr"`
  225. TransitionEntry bool `xml:"transitionEntry,attr,omitempty"`
  226. TabColor *xlsxTabColor `xml:"tabColor,omitempty"`
  227. OutlinePr *xlsxOutlinePr `xml:"outlinePr,omitempty"`
  228. PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
  229. }
  230. // xlsxOutlinePr maps to the outlinePr element
  231. // SummaryBelow allows you to adjust the direction of grouper controls
  232. type xlsxOutlinePr struct {
  233. SummaryBelow bool `xml:"summaryBelow,attr"`
  234. }
  235. // xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
  236. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
  237. // properties of the worksheet.
  238. type xlsxPageSetUpPr struct {
  239. AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"`
  240. FitToPage bool `xml:"fitToPage,attr,omitempty"` // Flag indicating whether the Fit to Page print option is enabled.
  241. }
  242. // xlsxTabColor directly maps the tabColor element in the namespace currently I
  243. // have not checked it for completeness - it does as much as I need.
  244. type xlsxTabColor struct {
  245. RGB string `xml:"rgb,attr,omitempty"`
  246. Theme int `xml:"theme,attr,omitempty"`
  247. Tint float64 `xml:"tint,attr,omitempty"`
  248. }
  249. // xlsxCols directly maps the cols element in the namespace
  250. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  251. // not checked it for completeness - it does as much as I need.
  252. type xlsxCols struct {
  253. XMLName xml.Name `xml:"cols"`
  254. Col []xlsxCol `xml:"col"`
  255. }
  256. // xlsxCol directly maps the col (Column Width & Formatting). Defines column
  257. // width and column formatting for one or more columns of the worksheet.
  258. type xlsxCol struct {
  259. BestFit bool `xml:"bestFit,attr,omitempty"`
  260. Collapsed bool `xml:"collapsed,attr,omitempty"`
  261. CustomWidth bool `xml:"customWidth,attr,omitempty"`
  262. Hidden bool `xml:"hidden,attr,omitempty"`
  263. Max int `xml:"max,attr"`
  264. Min int `xml:"min,attr"`
  265. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  266. Phonetic bool `xml:"phonetic,attr,omitempty"`
  267. Style int `xml:"style,attr,omitempty"`
  268. Width float64 `xml:"width,attr,omitempty"`
  269. }
  270. // xlsxDimension directly maps the dimension element in the namespace
  271. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element
  272. // specifies the used range of the worksheet. It specifies the row and column
  273. // bounds of used cells in the worksheet. This is optional and is not required.
  274. // Used cells include cells with formulas, text content, and cell formatting.
  275. // When an entire column is formatted, only the first cell in that column is
  276. // considered used.
  277. type xlsxDimension struct {
  278. XMLName xml.Name `xml:"dimension"`
  279. Ref string `xml:"ref,attr"`
  280. }
  281. // xlsxSheetData directly maps the sheetData element in the namespace
  282. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  283. // not checked it for completeness - it does as much as I need.
  284. type xlsxSheetData struct {
  285. XMLName xml.Name `xml:"sheetData"`
  286. Row []xlsxRow `xml:"row"`
  287. }
  288. // xlsxRow directly maps the row element. The element expresses information
  289. // about an entire row of a worksheet, and contains all cell definitions for a
  290. // particular row in the worksheet.
  291. type xlsxRow struct {
  292. Collapsed bool `xml:"collapsed,attr,omitempty"`
  293. CustomFormat bool `xml:"customFormat,attr,omitempty"`
  294. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  295. Hidden bool `xml:"hidden,attr,omitempty"`
  296. Ht float64 `xml:"ht,attr,omitempty"`
  297. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  298. Ph bool `xml:"ph,attr,omitempty"`
  299. R int `xml:"r,attr,omitempty"`
  300. S int `xml:"s,attr,omitempty"`
  301. Spans string `xml:"spans,attr,omitempty"`
  302. ThickBot bool `xml:"thickBot,attr,omitempty"`
  303. ThickTop bool `xml:"thickTop,attr,omitempty"`
  304. C []xlsxC `xml:"c"`
  305. }
  306. // xlsxSortState directly maps the sortState element. This collection
  307. // preserves the AutoFilter sort state.
  308. type xlsxSortState struct {
  309. ColumnSort bool `xml:"columnSort,attr,omitempty"`
  310. CaseSensitive bool `xml:"caseSensitive,attr,omitempty"`
  311. SortMethod string `xml:"sortMethod,attr,omitempty"`
  312. Ref string `xml:"ref,attr"`
  313. Content string `xml:",innerxml"`
  314. }
  315. // xlsxCustomSheetViews directly maps the customSheetViews element. This is a
  316. // collection of custom sheet views.
  317. type xlsxCustomSheetViews struct {
  318. XMLName xml.Name `xml:"customSheetViews"`
  319. CustomSheetView []*xlsxCustomSheetView `xml:"customSheetView"`
  320. }
  321. // xlsxBrk directly maps the row or column break to use when paginating a
  322. // worksheet.
  323. type xlsxBrk struct {
  324. ID int `xml:"id,attr,omitempty"`
  325. Min int `xml:"min,attr,omitempty"`
  326. Max int `xml:"max,attr,omitempty"`
  327. Man bool `xml:"man,attr,omitempty"`
  328. Pt bool `xml:"pt,attr,omitempty"`
  329. }
  330. // xlsxBreaks directly maps a collection of the row or column breaks.
  331. type xlsxBreaks struct {
  332. Brk []*xlsxBrk `xml:"brk"`
  333. Count int `xml:"count,attr,omitempty"`
  334. ManualBreakCount int `xml:"manualBreakCount,attr,omitempty"`
  335. }
  336. // xlsxCustomSheetView directly maps the customSheetView element.
  337. type xlsxCustomSheetView struct {
  338. Pane *xlsxPane `xml:"pane"`
  339. Selection *xlsxSelection `xml:"selection"`
  340. RowBreaks *xlsxBreaks `xml:"rowBreaks"`
  341. ColBreaks *xlsxBreaks `xml:"colBreaks"`
  342. PageMargins *xlsxPageMargins `xml:"pageMargins"`
  343. PrintOptions *xlsxPrintOptions `xml:"printOptions"`
  344. PageSetup *xlsxPageSetUp `xml:"pageSetup"`
  345. HeaderFooter *xlsxHeaderFooter `xml:"headerFooter"`
  346. AutoFilter *xlsxAutoFilter `xml:"autoFilter"`
  347. ExtLst *xlsxExtLst `xml:"extLst"`
  348. GUID string `xml:"guid,attr"`
  349. Scale int `xml:"scale,attr,omitempty"`
  350. ColorID int `xml:"colorId,attr,omitempty"`
  351. ShowPageBreaks bool `xml:"showPageBreaks,attr,omitempty"`
  352. ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
  353. ShowGridLines bool `xml:"showGridLines,attr,omitempty"`
  354. ShowRowCol bool `xml:"showRowCol,attr,omitempty"`
  355. OutlineSymbols bool `xml:"outlineSymbols,attr,omitempty"`
  356. ZeroValues bool `xml:"zeroValues,attr,omitempty"`
  357. FitToPage bool `xml:"fitToPage,attr,omitempty"`
  358. PrintArea bool `xml:"printArea,attr,omitempty"`
  359. Filter bool `xml:"filter,attr,omitempty"`
  360. ShowAutoFilter bool `xml:"showAutoFilter,attr,omitempty"`
  361. HiddenRows bool `xml:"hiddenRows,attr,omitempty"`
  362. HiddenColumns bool `xml:"hiddenColumns,attr,omitempty"`
  363. State string `xml:"state,attr,omitempty"`
  364. FilterUnique bool `xml:"filterUnique,attr,omitempty"`
  365. View string `xml:"view,attr,omitempty"`
  366. ShowRuler bool `xml:"showRuler,attr,omitempty"`
  367. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  368. }
  369. // xlsxMergeCell directly maps the mergeCell element. A single merged cell.
  370. type xlsxMergeCell struct {
  371. Ref string `xml:"ref,attr,omitempty"`
  372. }
  373. // xlsxMergeCells directly maps the mergeCells element. This collection
  374. // expresses all the merged cells in the sheet.
  375. type xlsxMergeCells struct {
  376. XMLName xml.Name `xml:"mergeCells"`
  377. Count int `xml:"count,attr,omitempty"`
  378. Cells []*xlsxMergeCell `xml:"mergeCell,omitempty"`
  379. }
  380. // xlsxDataValidations expresses all data validation information for cells in a
  381. // sheet which have data validation features applied.
  382. type xlsxDataValidations struct {
  383. XMLName xml.Name `xml:"dataValidations"`
  384. Count int `xml:"count,attr,omitempty"`
  385. DisablePrompts bool `xml:"disablePrompts,attr,omitempty"`
  386. XWindow int `xml:"xWindow,attr,omitempty"`
  387. YWindow int `xml:"yWindow,attr,omitempty"`
  388. DataValidation []*DataValidation `xml:"dataValidation"`
  389. }
  390. // DataValidation directly maps the a single item of data validation defined
  391. // on a range of the worksheet.
  392. type DataValidation struct {
  393. AllowBlank bool `xml:"allowBlank,attr"`
  394. Error *string `xml:"error,attr"`
  395. ErrorStyle *string `xml:"errorStyle,attr"`
  396. ErrorTitle *string `xml:"errorTitle,attr"`
  397. Operator string `xml:"operator,attr,omitempty"`
  398. Prompt *string `xml:"prompt,attr"`
  399. PromptTitle *string `xml:"promptTitle,attr"`
  400. ShowDropDown bool `xml:"showDropDown,attr,omitempty"`
  401. ShowErrorMessage bool `xml:"showErrorMessage,attr,omitempty"`
  402. ShowInputMessage bool `xml:"showInputMessage,attr,omitempty"`
  403. Sqref string `xml:"sqref,attr"`
  404. Type string `xml:"type,attr,omitempty"`
  405. Formula1 string `xml:",innerxml"`
  406. Formula2 string `xml:",innerxml"`
  407. }
  408. // xlsxC directly maps the c element in the namespace
  409. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  410. // not checked it for completeness - it does as much as I need.
  411. //
  412. // This simple type is restricted to the values listed in the following table:
  413. //
  414. // Enumeration Value | Description
  415. // ---------------------------+---------------------------------
  416. // b (Boolean) | Cell containing a boolean.
  417. // d (Date) | Cell contains a date in the ISO 8601 format.
  418. // e (Error) | Cell containing an error.
  419. // 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).
  420. // n (Number) | Cell containing a number.
  421. // s (Shared String) | Cell containing a shared string.
  422. // str (String) | Cell containing a formula string.
  423. //
  424. type xlsxC struct {
  425. XMLName xml.Name `xml:"c"`
  426. XMLSpace xml.Attr `xml:"space,attr,omitempty"`
  427. R string `xml:"r,attr,omitempty"` // Cell ID, e.g. A1
  428. S int `xml:"s,attr,omitempty"` // Style reference.
  429. // Str string `xml:"str,attr,omitempty"` // Style reference.
  430. T string `xml:"t,attr,omitempty"` // Type.
  431. F *xlsxF `xml:"f,omitempty"` // Formula
  432. V string `xml:"v,omitempty"` // Value
  433. IS *xlsxSI `xml:"is"`
  434. }
  435. func (c *xlsxC) hasValue() bool {
  436. return c.S != 0 || c.V != "" || c.F != nil || c.T != ""
  437. }
  438. // xlsxF directly maps the f element in the namespace
  439. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  440. // not checked it for completeness - it does as much as I need.
  441. type xlsxF struct {
  442. Content string `xml:",chardata"`
  443. T string `xml:"t,attr,omitempty"` // Formula type
  444. Ref string `xml:"ref,attr,omitempty"` // Shared formula ref
  445. Si string `xml:"si,attr,omitempty"` // Shared formula index
  446. }
  447. // xlsxSheetProtection collection expresses the sheet protection options to
  448. // enforce when the sheet is protected.
  449. type xlsxSheetProtection struct {
  450. XMLName xml.Name `xml:"sheetProtection"`
  451. AlgorithmName string `xml:"algorithmName,attr,omitempty"`
  452. Password string `xml:"password,attr,omitempty"`
  453. HashValue string `xml:"hashValue,attr,omitempty"`
  454. SaltValue string `xml:"saltValue,attr,omitempty"`
  455. SpinCount int `xml:"spinCount,attr,omitempty"`
  456. Sheet bool `xml:"sheet,attr"`
  457. Objects bool `xml:"objects,attr"`
  458. Scenarios bool `xml:"scenarios,attr"`
  459. FormatCells bool `xml:"formatCells,attr"`
  460. FormatColumns bool `xml:"formatColumns,attr"`
  461. FormatRows bool `xml:"formatRows,attr"`
  462. InsertColumns bool `xml:"insertColumns,attr"`
  463. InsertRows bool `xml:"insertRows,attr"`
  464. InsertHyperlinks bool `xml:"insertHyperlinks,attr"`
  465. DeleteColumns bool `xml:"deleteColumns,attr"`
  466. DeleteRows bool `xml:"deleteRows,attr"`
  467. SelectLockedCells bool `xml:"selectLockedCells,attr"`
  468. Sort bool `xml:"sort,attr"`
  469. AutoFilter bool `xml:"autoFilter,attr"`
  470. PivotTables bool `xml:"pivotTables,attr"`
  471. SelectUnlockedCells bool `xml:"selectUnlockedCells,attr"`
  472. }
  473. // xlsxPhoneticPr (Phonetic Properties) represents a collection of phonetic
  474. // properties that affect the display of phonetic text for this String Item
  475. // (si). Phonetic text is used to give hints as to the pronunciation of an East
  476. // Asian language, and the hints are displayed as text within the spreadsheet
  477. // cells across the top portion of the cell. Since the phonetic hints are text,
  478. // every phonetic hint is expressed as a phonetic run (rPh), and these
  479. // properties specify how to display that phonetic run.
  480. type xlsxPhoneticPr struct {
  481. XMLName xml.Name `xml:"phoneticPr"`
  482. Alignment string `xml:"alignment,attr,omitempty"`
  483. FontID *int `xml:"fontId,attr"`
  484. Type string `xml:"type,attr,omitempty"`
  485. }
  486. // A Conditional Format is a format, such as cell shading or font color, that a
  487. // spreadsheet application can automatically apply to cells if a specified
  488. // condition is true. This collection expresses conditional formatting rules
  489. // applied to a particular cell or range.
  490. type xlsxConditionalFormatting struct {
  491. XMLName xml.Name `xml:"conditionalFormatting"`
  492. SQRef string `xml:"sqref,attr,omitempty"`
  493. CfRule []*xlsxCfRule `xml:"cfRule"`
  494. }
  495. // xlsxCfRule (Conditional Formatting Rule) represents a description of a
  496. // conditional formatting rule.
  497. type xlsxCfRule struct {
  498. AboveAverage *bool `xml:"aboveAverage,attr"`
  499. Bottom bool `xml:"bottom,attr,omitempty"`
  500. DxfID *int `xml:"dxfId,attr"`
  501. EqualAverage bool `xml:"equalAverage,attr,omitempty"`
  502. Operator string `xml:"operator,attr,omitempty"`
  503. Percent bool `xml:"percent,attr,omitempty"`
  504. Priority int `xml:"priority,attr,omitempty"`
  505. Rank int `xml:"rank,attr,omitempty"`
  506. StdDev int `xml:"stdDev,attr,omitempty"`
  507. StopIfTrue bool `xml:"stopIfTrue,attr,omitempty"`
  508. Text string `xml:"text,attr,omitempty"`
  509. TimePeriod string `xml:"timePeriod,attr,omitempty"`
  510. Type string `xml:"type,attr,omitempty"`
  511. Formula []string `xml:"formula,omitempty"`
  512. ColorScale *xlsxColorScale `xml:"colorScale"`
  513. DataBar *xlsxDataBar `xml:"dataBar"`
  514. IconSet *xlsxIconSet `xml:"iconSet"`
  515. ExtLst *xlsxExtLst `xml:"extLst"`
  516. }
  517. // xlsxColorScale (Color Scale) describes a gradated color scale in this
  518. // conditional formatting rule.
  519. type xlsxColorScale struct {
  520. Cfvo []*xlsxCfvo `xml:"cfvo"`
  521. Color []*xlsxColor `xml:"color"`
  522. }
  523. // dataBar (Data Bar) describes a data bar conditional formatting rule.
  524. type xlsxDataBar struct {
  525. MaxLength int `xml:"maxLength,attr,omitempty"`
  526. MinLength int `xml:"minLength,attr,omitempty"`
  527. ShowValue bool `xml:"showValue,attr,omitempty"`
  528. Cfvo []*xlsxCfvo `xml:"cfvo"`
  529. Color []*xlsxColor `xml:"color"`
  530. }
  531. // xlsxIconSet (Icon Set) describes an icon set conditional formatting rule.
  532. type xlsxIconSet struct {
  533. Cfvo []*xlsxCfvo `xml:"cfvo"`
  534. IconSet string `xml:"iconSet,attr,omitempty"`
  535. ShowValue bool `xml:"showValue,attr,omitempty"`
  536. Percent bool `xml:"percent,attr,omitempty"`
  537. Reverse bool `xml:"reverse,attr,omitempty"`
  538. }
  539. // cfvo (Conditional Format Value Object) describes the values of the
  540. // interpolation points in a gradient scale.
  541. type xlsxCfvo struct {
  542. Gte bool `xml:"gte,attr,omitempty"`
  543. Type string `xml:"type,attr,omitempty"`
  544. Val string `xml:"val,attr,omitempty"`
  545. ExtLst *xlsxExtLst `xml:"extLst"`
  546. }
  547. // xlsxHyperlinks directly maps the hyperlinks element in the namespace
  548. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - A hyperlink can
  549. // be stored in a package as a relationship. Hyperlinks shall be identified by
  550. // containing a target which specifies the destination of the given hyperlink.
  551. type xlsxHyperlinks struct {
  552. XMLName xml.Name `xml:"hyperlinks"`
  553. Hyperlink []xlsxHyperlink `xml:"hyperlink"`
  554. }
  555. // xlsxHyperlink directly maps the hyperlink element in the namespace
  556. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  557. type xlsxHyperlink struct {
  558. Ref string `xml:"ref,attr"`
  559. Location string `xml:"location,attr,omitempty"`
  560. Display string `xml:"display,attr,omitempty"`
  561. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  562. }
  563. // xlsxTableParts directly maps the tableParts element in the namespace
  564. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - The table element
  565. // has several attributes applied to identify the table and the data range it
  566. // covers. The table id attribute needs to be unique across all table parts, the
  567. // same goes for the name and displayName. The displayName has the further
  568. // restriction that it must be unique across all defined names in the workbook.
  569. // Later on we will see that you can define names for many elements, such as
  570. // cells or formulas. The name value is used for the object model in Microsoft
  571. // Office Excel. The displayName is used for references in formulas. The ref
  572. // attribute is used to identify the cell range that the table covers. This
  573. // includes not only the table data, but also the table header containing column
  574. // names.
  575. // To add columns to your table you add new tableColumn elements to the
  576. // tableColumns container. Similar to the shared string table the collection
  577. // keeps a count attribute identifying the number of columns. Besides the table
  578. // definition in the table part there is also the need to identify which tables
  579. // are displayed in the worksheet. The worksheet part has a separate element
  580. // tableParts to store this information. Each table part is referenced through
  581. // the relationship ID and again a count of the number of table parts is
  582. // maintained. The following markup sample is taken from the documents
  583. // accompanying this book. The sheet data element has been removed to reduce the
  584. // size of the sample. To reference the table, just add the tableParts element,
  585. // of course after having created and stored the table part. For example:
  586. //
  587. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  588. // ...
  589. // <tableParts count="1">
  590. // <tablePart r:id="rId1" />
  591. // </tableParts>
  592. // </worksheet>
  593. //
  594. type xlsxTableParts struct {
  595. XMLName xml.Name `xml:"tableParts"`
  596. Count int `xml:"count,attr,omitempty"`
  597. TableParts []*xlsxTablePart `xml:"tablePart"`
  598. }
  599. // xlsxTablePart directly maps the tablePart element in the namespace
  600. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  601. type xlsxTablePart struct {
  602. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  603. }
  604. // xlsxPicture directly maps the picture element in the namespace
  605. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet
  606. // image. For example:
  607. //
  608. // <picture r:id="rId1"/>
  609. //
  610. type xlsxPicture struct {
  611. XMLName xml.Name `xml:"picture"`
  612. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  613. }
  614. // xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace
  615. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - A comment is a
  616. // rich text note that is attached to, and associated with, a cell, separate
  617. // from other cell content. Comment content is stored separate from the cell,
  618. // and is displayed in a drawing object (like a text box) that is separate from,
  619. // but associated with, a cell. Comments are used as reminders, such as noting
  620. // how a complex formula works, or to provide feedback to other users. Comments
  621. // can also be used to explain assumptions made in a formula or to call out
  622. // something special about the cell.
  623. type xlsxLegacyDrawing struct {
  624. XMLName xml.Name `xml:"legacyDrawing"`
  625. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  626. }
  627. // xlsxLegacyDrawingHF specifies the explicit relationship to the part
  628. // containing the VML defining pictures rendered in the header / footer of the
  629. // sheet.
  630. type xlsxLegacyDrawingHF struct {
  631. XMLName xml.Name `xml:"legacyDrawingHF"`
  632. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  633. }
  634. type xlsxInnerXML struct {
  635. Content string `xml:",innerxml"`
  636. }
  637. // xlsxWorksheetExt directly maps the ext element in the worksheet.
  638. type xlsxWorksheetExt struct {
  639. XMLName xml.Name `xml:"ext"`
  640. URI string `xml:"uri,attr"`
  641. Content string `xml:",innerxml"`
  642. }
  643. // decodeWorksheetExt directly maps the ext element.
  644. type decodeWorksheetExt struct {
  645. XMLName xml.Name `xml:"extLst"`
  646. Ext []*xlsxWorksheetExt `xml:"ext"`
  647. }
  648. // decodeX14SparklineGroups directly maps the sparklineGroups element.
  649. type decodeX14SparklineGroups struct {
  650. XMLName xml.Name `xml:"sparklineGroups"`
  651. XMLNSXM string `xml:"xmlns:xm,attr"`
  652. Content string `xml:",innerxml"`
  653. }
  654. // xlsxX14SparklineGroups directly maps the sparklineGroups element.
  655. type xlsxX14SparklineGroups struct {
  656. XMLName xml.Name `xml:"x14:sparklineGroups"`
  657. XMLNSXM string `xml:"xmlns:xm,attr"`
  658. SparklineGroups []*xlsxX14SparklineGroup `xml:"x14:sparklineGroup"`
  659. Content string `xml:",innerxml"`
  660. }
  661. // xlsxX14SparklineGroup directly maps the sparklineGroup element.
  662. type xlsxX14SparklineGroup struct {
  663. XMLName xml.Name `xml:"x14:sparklineGroup"`
  664. ManualMax int `xml:"manualMax,attr,omitempty"`
  665. ManualMin int `xml:"manualMin,attr,omitempty"`
  666. LineWeight float64 `xml:"lineWeight,attr,omitempty"`
  667. Type string `xml:"type,attr,omitempty"`
  668. DateAxis bool `xml:"dateAxis,attr,omitempty"`
  669. DisplayEmptyCellsAs string `xml:"displayEmptyCellsAs,attr,omitempty"`
  670. Markers bool `xml:"markers,attr,omitempty"`
  671. High bool `xml:"high,attr,omitempty"`
  672. Low bool `xml:"low,attr,omitempty"`
  673. First bool `xml:"first,attr,omitempty"`
  674. Last bool `xml:"last,attr,omitempty"`
  675. Negative bool `xml:"negative,attr,omitempty"`
  676. DisplayXAxis bool `xml:"displayXAxis,attr,omitempty"`
  677. DisplayHidden bool `xml:"displayHidden,attr,omitempty"`
  678. MinAxisType string `xml:"minAxisType,attr,omitempty"`
  679. MaxAxisType string `xml:"maxAxisType,attr,omitempty"`
  680. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  681. ColorSeries *xlsxTabColor `xml:"x14:colorSeries"`
  682. ColorNegative *xlsxTabColor `xml:"x14:colorNegative"`
  683. ColorAxis *xlsxColor `xml:"x14:colorAxis"`
  684. ColorMarkers *xlsxTabColor `xml:"x14:colorMarkers"`
  685. ColorFirst *xlsxTabColor `xml:"x14:colorFirst"`
  686. ColorLast *xlsxTabColor `xml:"x14:colorLast"`
  687. ColorHigh *xlsxTabColor `xml:"x14:colorHigh"`
  688. ColorLow *xlsxTabColor `xml:"x14:colorLow"`
  689. Sparklines xlsxX14Sparklines `xml:"x14:sparklines"`
  690. }
  691. // xlsxX14Sparklines directly maps the sparklines element.
  692. type xlsxX14Sparklines struct {
  693. Sparkline []*xlsxX14Sparkline `xml:"x14:sparkline"`
  694. }
  695. // xlsxX14Sparkline directly maps the sparkline element.
  696. type xlsxX14Sparkline struct {
  697. F string `xml:"xm:f"`
  698. Sqref string `xml:"xm:sqref"`
  699. }
  700. // SparklineOption directly maps the settings of the sparkline.
  701. type SparklineOption struct {
  702. Location []string
  703. Range []string
  704. Max int
  705. CustMax int
  706. Min int
  707. CustMin int
  708. Type string
  709. Weight float64
  710. DateAxis bool
  711. Markers bool
  712. High bool
  713. Low bool
  714. First bool
  715. Last bool
  716. Negative bool
  717. Axis bool
  718. Hidden bool
  719. Reverse bool
  720. Style int
  721. SeriesColor string
  722. NegativeColor string
  723. MarkersColor string
  724. FirstColor string
  725. LastColor string
  726. HightColor string
  727. LowColor string
  728. EmptyCells string
  729. }
  730. // formatPanes directly maps the settings of the panes.
  731. type formatPanes struct {
  732. Freeze bool `json:"freeze"`
  733. Split bool `json:"split"`
  734. XSplit int `json:"x_split"`
  735. YSplit int `json:"y_split"`
  736. TopLeftCell string `json:"top_left_cell"`
  737. ActivePane string `json:"active_pane"`
  738. Panes []struct {
  739. SQRef string `json:"sqref"`
  740. ActiveCell string `json:"active_cell"`
  741. Pane string `json:"pane"`
  742. } `json:"panes"`
  743. }
  744. // formatConditional directly maps the conditional format settings of the cells.
  745. type formatConditional struct {
  746. Type string `json:"type"`
  747. AboveAverage bool `json:"above_average"`
  748. Percent bool `json:"percent"`
  749. Format int `json:"format"`
  750. Criteria string `json:"criteria"`
  751. Value string `json:"value,omitempty"`
  752. Minimum string `json:"minimum,omitempty"`
  753. Maximum string `json:"maximum,omitempty"`
  754. MinType string `json:"min_type,omitempty"`
  755. MidType string `json:"mid_type,omitempty"`
  756. MaxType string `json:"max_type,omitempty"`
  757. MinValue string `json:"min_value,omitempty"`
  758. MidValue string `json:"mid_value,omitempty"`
  759. MaxValue string `json:"max_value,omitempty"`
  760. MinColor string `json:"min_color,omitempty"`
  761. MidColor string `json:"mid_color,omitempty"`
  762. MaxColor string `json:"max_color,omitempty"`
  763. MinLength string `json:"min_length,omitempty"`
  764. MaxLength string `json:"max_length,omitempty"`
  765. MultiRange string `json:"multi_range,omitempty"`
  766. BarColor string `json:"bar_color,omitempty"`
  767. }
  768. // FormatSheetProtection directly maps the settings of worksheet protection.
  769. type FormatSheetProtection struct {
  770. AutoFilter bool
  771. DeleteColumns bool
  772. DeleteRows bool
  773. EditObjects bool
  774. EditScenarios bool
  775. FormatCells bool
  776. FormatColumns bool
  777. FormatRows bool
  778. InsertColumns bool
  779. InsertHyperlinks bool
  780. InsertRows bool
  781. Password string
  782. PivotTables bool
  783. SelectLockedCells bool
  784. SelectUnlockedCells bool
  785. Sort bool
  786. }
  787. // FormatHeaderFooter directly maps the settings of header and footer.
  788. type FormatHeaderFooter struct {
  789. AlignWithMargins bool
  790. DifferentFirst bool
  791. DifferentOddEven bool
  792. ScaleWithDoc bool
  793. OddHeader string
  794. OddFooter string
  795. EvenHeader string
  796. EvenFooter string
  797. FirstFooter string
  798. FirstHeader string
  799. }
  800. // FormatPageMargins directly maps the settings of page margins
  801. type FormatPageMargins struct {
  802. Bottom string
  803. Footer string
  804. Header string
  805. Left string
  806. Right string
  807. Top string
  808. }