xmlWorksheet.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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 int `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,omitempty"`
  236. SummaryRight bool `xml:"summaryRight,attr,omitempty"`
  237. ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr,omitempty"`
  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. SQRef string `xml:"sqref,attr,omitempty"`
  494. CfRule []*xlsxCfRule `xml:"cfRule"`
  495. }
  496. // xlsxCfRule (Conditional Formatting Rule) represents a description of a
  497. // conditional formatting rule.
  498. type xlsxCfRule struct {
  499. AboveAverage *bool `xml:"aboveAverage,attr"`
  500. Bottom bool `xml:"bottom,attr,omitempty"`
  501. DxfID *int `xml:"dxfId,attr"`
  502. EqualAverage bool `xml:"equalAverage,attr,omitempty"`
  503. Operator string `xml:"operator,attr,omitempty"`
  504. Percent bool `xml:"percent,attr,omitempty"`
  505. Priority int `xml:"priority,attr,omitempty"`
  506. Rank int `xml:"rank,attr,omitempty"`
  507. StdDev int `xml:"stdDev,attr,omitempty"`
  508. StopIfTrue bool `xml:"stopIfTrue,attr,omitempty"`
  509. Text string `xml:"text,attr,omitempty"`
  510. TimePeriod string `xml:"timePeriod,attr,omitempty"`
  511. Type string `xml:"type,attr,omitempty"`
  512. Formula []string `xml:"formula,omitempty"`
  513. ColorScale *xlsxColorScale `xml:"colorScale"`
  514. DataBar *xlsxDataBar `xml:"dataBar"`
  515. IconSet *xlsxIconSet `xml:"iconSet"`
  516. ExtLst *xlsxExtLst `xml:"extLst"`
  517. }
  518. // xlsxColorScale (Color Scale) describes a gradated color scale in this
  519. // conditional formatting rule.
  520. type xlsxColorScale struct {
  521. Cfvo []*xlsxCfvo `xml:"cfvo"`
  522. Color []*xlsxColor `xml:"color"`
  523. }
  524. // dataBar (Data Bar) describes a data bar conditional formatting rule.
  525. type xlsxDataBar struct {
  526. MaxLength int `xml:"maxLength,attr,omitempty"`
  527. MinLength int `xml:"minLength,attr,omitempty"`
  528. ShowValue bool `xml:"showValue,attr,omitempty"`
  529. Cfvo []*xlsxCfvo `xml:"cfvo"`
  530. Color []*xlsxColor `xml:"color"`
  531. }
  532. // xlsxIconSet (Icon Set) describes an icon set conditional formatting rule.
  533. type xlsxIconSet struct {
  534. Cfvo []*xlsxCfvo `xml:"cfvo"`
  535. IconSet string `xml:"iconSet,attr,omitempty"`
  536. ShowValue bool `xml:"showValue,attr,omitempty"`
  537. Percent bool `xml:"percent,attr,omitempty"`
  538. Reverse bool `xml:"reverse,attr,omitempty"`
  539. }
  540. // cfvo (Conditional Format Value Object) describes the values of the
  541. // interpolation points in a gradient scale.
  542. type xlsxCfvo struct {
  543. Gte bool `xml:"gte,attr,omitempty"`
  544. Type string `xml:"type,attr,omitempty"`
  545. Val string `xml:"val,attr,omitempty"`
  546. ExtLst *xlsxExtLst `xml:"extLst"`
  547. }
  548. // xlsxHyperlinks directly maps the hyperlinks element in the namespace
  549. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - A hyperlink can
  550. // be stored in a package as a relationship. Hyperlinks shall be identified by
  551. // containing a target which specifies the destination of the given hyperlink.
  552. type xlsxHyperlinks struct {
  553. XMLName xml.Name `xml:"hyperlinks"`
  554. Hyperlink []xlsxHyperlink `xml:"hyperlink"`
  555. }
  556. // xlsxHyperlink directly maps the hyperlink element in the namespace
  557. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  558. type xlsxHyperlink struct {
  559. Ref string `xml:"ref,attr"`
  560. Location string `xml:"location,attr,omitempty"`
  561. Display string `xml:"display,attr,omitempty"`
  562. Tooltip string `xml:"tooltip,attr,omitempty"`
  563. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  564. }
  565. // xlsxTableParts directly maps the tableParts element in the namespace
  566. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - The table element
  567. // has several attributes applied to identify the table and the data range it
  568. // covers. The table id attribute needs to be unique across all table parts, the
  569. // same goes for the name and displayName. The displayName has the further
  570. // restriction that it must be unique across all defined names in the workbook.
  571. // Later on we will see that you can define names for many elements, such as
  572. // cells or formulas. The name value is used for the object model in Microsoft
  573. // Office Excel. The displayName is used for references in formulas. The ref
  574. // attribute is used to identify the cell range that the table covers. This
  575. // includes not only the table data, but also the table header containing column
  576. // names.
  577. // To add columns to your table you add new tableColumn elements to the
  578. // tableColumns container. Similar to the shared string table the collection
  579. // keeps a count attribute identifying the number of columns. Besides the table
  580. // definition in the table part there is also the need to identify which tables
  581. // are displayed in the worksheet. The worksheet part has a separate element
  582. // tableParts to store this information. Each table part is referenced through
  583. // the relationship ID and again a count of the number of table parts is
  584. // maintained. The following markup sample is taken from the documents
  585. // accompanying this book. The sheet data element has been removed to reduce the
  586. // size of the sample. To reference the table, just add the tableParts element,
  587. // of course after having created and stored the table part. For example:
  588. //
  589. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  590. // ...
  591. // <tableParts count="1">
  592. // <tablePart r:id="rId1" />
  593. // </tableParts>
  594. // </worksheet>
  595. //
  596. type xlsxTableParts struct {
  597. XMLName xml.Name `xml:"tableParts"`
  598. Count int `xml:"count,attr,omitempty"`
  599. TableParts []*xlsxTablePart `xml:"tablePart"`
  600. }
  601. // xlsxTablePart directly maps the tablePart element in the namespace
  602. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  603. type xlsxTablePart struct {
  604. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  605. }
  606. // xlsxPicture directly maps the picture element in the namespace
  607. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet
  608. // image. For example:
  609. //
  610. // <picture r:id="rId1"/>
  611. //
  612. type xlsxPicture struct {
  613. XMLName xml.Name `xml:"picture"`
  614. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  615. }
  616. // xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace
  617. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - A comment is a
  618. // rich text note that is attached to, and associated with, a cell, separate
  619. // from other cell content. Comment content is stored separate from the cell,
  620. // and is displayed in a drawing object (like a text box) that is separate from,
  621. // but associated with, a cell. Comments are used as reminders, such as noting
  622. // how a complex formula works, or to provide feedback to other users. Comments
  623. // can also be used to explain assumptions made in a formula or to call out
  624. // something special about the cell.
  625. type xlsxLegacyDrawing struct {
  626. XMLName xml.Name `xml:"legacyDrawing"`
  627. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  628. }
  629. // xlsxLegacyDrawingHF specifies the explicit relationship to the part
  630. // containing the VML defining pictures rendered in the header / footer of the
  631. // sheet.
  632. type xlsxLegacyDrawingHF struct {
  633. XMLName xml.Name `xml:"legacyDrawingHF"`
  634. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  635. }
  636. type xlsxInnerXML struct {
  637. Content string `xml:",innerxml"`
  638. }
  639. // xlsxWorksheetExt directly maps the ext element in the worksheet.
  640. type xlsxWorksheetExt struct {
  641. XMLName xml.Name `xml:"ext"`
  642. URI string `xml:"uri,attr"`
  643. Content string `xml:",innerxml"`
  644. }
  645. // decodeWorksheetExt directly maps the ext element.
  646. type decodeWorksheetExt struct {
  647. XMLName xml.Name `xml:"extLst"`
  648. Ext []*xlsxWorksheetExt `xml:"ext"`
  649. }
  650. // decodeX14SparklineGroups directly maps the sparklineGroups element.
  651. type decodeX14SparklineGroups struct {
  652. XMLName xml.Name `xml:"sparklineGroups"`
  653. XMLNSXM string `xml:"xmlns:xm,attr"`
  654. Content string `xml:",innerxml"`
  655. }
  656. // xlsxX14SparklineGroups directly maps the sparklineGroups element.
  657. type xlsxX14SparklineGroups struct {
  658. XMLName xml.Name `xml:"x14:sparklineGroups"`
  659. XMLNSXM string `xml:"xmlns:xm,attr"`
  660. SparklineGroups []*xlsxX14SparklineGroup `xml:"x14:sparklineGroup"`
  661. Content string `xml:",innerxml"`
  662. }
  663. // xlsxX14SparklineGroup directly maps the sparklineGroup element.
  664. type xlsxX14SparklineGroup struct {
  665. XMLName xml.Name `xml:"x14:sparklineGroup"`
  666. ManualMax int `xml:"manualMax,attr,omitempty"`
  667. ManualMin int `xml:"manualMin,attr,omitempty"`
  668. LineWeight float64 `xml:"lineWeight,attr,omitempty"`
  669. Type string `xml:"type,attr,omitempty"`
  670. DateAxis bool `xml:"dateAxis,attr,omitempty"`
  671. DisplayEmptyCellsAs string `xml:"displayEmptyCellsAs,attr,omitempty"`
  672. Markers bool `xml:"markers,attr,omitempty"`
  673. High bool `xml:"high,attr,omitempty"`
  674. Low bool `xml:"low,attr,omitempty"`
  675. First bool `xml:"first,attr,omitempty"`
  676. Last bool `xml:"last,attr,omitempty"`
  677. Negative bool `xml:"negative,attr,omitempty"`
  678. DisplayXAxis bool `xml:"displayXAxis,attr,omitempty"`
  679. DisplayHidden bool `xml:"displayHidden,attr,omitempty"`
  680. MinAxisType string `xml:"minAxisType,attr,omitempty"`
  681. MaxAxisType string `xml:"maxAxisType,attr,omitempty"`
  682. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  683. ColorSeries *xlsxTabColor `xml:"x14:colorSeries"`
  684. ColorNegative *xlsxTabColor `xml:"x14:colorNegative"`
  685. ColorAxis *xlsxColor `xml:"x14:colorAxis"`
  686. ColorMarkers *xlsxTabColor `xml:"x14:colorMarkers"`
  687. ColorFirst *xlsxTabColor `xml:"x14:colorFirst"`
  688. ColorLast *xlsxTabColor `xml:"x14:colorLast"`
  689. ColorHigh *xlsxTabColor `xml:"x14:colorHigh"`
  690. ColorLow *xlsxTabColor `xml:"x14:colorLow"`
  691. Sparklines xlsxX14Sparklines `xml:"x14:sparklines"`
  692. }
  693. // xlsxX14Sparklines directly maps the sparklines element.
  694. type xlsxX14Sparklines struct {
  695. Sparkline []*xlsxX14Sparkline `xml:"x14:sparkline"`
  696. }
  697. // xlsxX14Sparkline directly maps the sparkline element.
  698. type xlsxX14Sparkline struct {
  699. F string `xml:"xm:f"`
  700. Sqref string `xml:"xm:sqref"`
  701. }
  702. // SparklineOption directly maps the settings of the sparkline.
  703. type SparklineOption struct {
  704. Location []string
  705. Range []string
  706. Max int
  707. CustMax int
  708. Min int
  709. CustMin int
  710. Type string
  711. Weight float64
  712. DateAxis bool
  713. Markers bool
  714. High bool
  715. Low bool
  716. First bool
  717. Last bool
  718. Negative bool
  719. Axis bool
  720. Hidden bool
  721. Reverse bool
  722. Style int
  723. SeriesColor string
  724. NegativeColor string
  725. MarkersColor string
  726. FirstColor string
  727. LastColor string
  728. HightColor string
  729. LowColor string
  730. EmptyCells string
  731. }
  732. // formatPanes directly maps the settings of the panes.
  733. type formatPanes struct {
  734. Freeze bool `json:"freeze"`
  735. Split bool `json:"split"`
  736. XSplit int `json:"x_split"`
  737. YSplit int `json:"y_split"`
  738. TopLeftCell string `json:"top_left_cell"`
  739. ActivePane string `json:"active_pane"`
  740. Panes []struct {
  741. SQRef string `json:"sqref"`
  742. ActiveCell string `json:"active_cell"`
  743. Pane string `json:"pane"`
  744. } `json:"panes"`
  745. }
  746. // formatConditional directly maps the conditional format settings of the cells.
  747. type formatConditional struct {
  748. Type string `json:"type"`
  749. AboveAverage bool `json:"above_average"`
  750. Percent bool `json:"percent"`
  751. Format int `json:"format"`
  752. Criteria string `json:"criteria"`
  753. Value string `json:"value,omitempty"`
  754. Minimum string `json:"minimum,omitempty"`
  755. Maximum string `json:"maximum,omitempty"`
  756. MinType string `json:"min_type,omitempty"`
  757. MidType string `json:"mid_type,omitempty"`
  758. MaxType string `json:"max_type,omitempty"`
  759. MinValue string `json:"min_value,omitempty"`
  760. MidValue string `json:"mid_value,omitempty"`
  761. MaxValue string `json:"max_value,omitempty"`
  762. MinColor string `json:"min_color,omitempty"`
  763. MidColor string `json:"mid_color,omitempty"`
  764. MaxColor string `json:"max_color,omitempty"`
  765. MinLength string `json:"min_length,omitempty"`
  766. MaxLength string `json:"max_length,omitempty"`
  767. MultiRange string `json:"multi_range,omitempty"`
  768. BarColor string `json:"bar_color,omitempty"`
  769. }
  770. // FormatSheetProtection directly maps the settings of worksheet protection.
  771. type FormatSheetProtection struct {
  772. AutoFilter bool
  773. DeleteColumns bool
  774. DeleteRows bool
  775. EditObjects bool
  776. EditScenarios bool
  777. FormatCells bool
  778. FormatColumns bool
  779. FormatRows bool
  780. InsertColumns bool
  781. InsertHyperlinks bool
  782. InsertRows bool
  783. Password string
  784. PivotTables bool
  785. SelectLockedCells bool
  786. SelectUnlockedCells bool
  787. Sort bool
  788. }
  789. // FormatHeaderFooter directly maps the settings of header and footer.
  790. type FormatHeaderFooter struct {
  791. AlignWithMargins bool
  792. DifferentFirst bool
  793. DifferentOddEven bool
  794. ScaleWithDoc bool
  795. OddHeader string
  796. OddFooter string
  797. EvenHeader string
  798. EvenFooter string
  799. FirstFooter string
  800. FirstHeader string
  801. }
  802. // FormatPageMargins directly maps the settings of page margins
  803. type FormatPageMargins struct {
  804. Bottom string
  805. Footer string
  806. Header string
  807. Left string
  808. Right string
  809. Top string
  810. }