xmlWorksheet.go 39 KB

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