xmlWorksheet.go 40 KB

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