xmlWorksheet.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. // Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX / XLSM / XLTM files. Supports reading and writing
  7. // spreadsheet documents generated by Microsoft Exce™ 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.10 or later.
  11. package excelize
  12. import "encoding/xml"
  13. // xlsxWorksheet directly maps the worksheet element in the namespace
  14. // http://schemas.openxmlformats.org/spreadsheetml/2006/main.
  15. type xlsxWorksheet struct {
  16. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
  17. SheetPr *xlsxSheetPr `xml:"sheetPr"`
  18. Dimension *xlsxDimension `xml:"dimension"`
  19. SheetViews *xlsxSheetViews `xml:"sheetViews"`
  20. SheetFormatPr *xlsxSheetFormatPr `xml:"sheetFormatPr"`
  21. Cols *xlsxCols `xml:"cols"`
  22. SheetData xlsxSheetData `xml:"sheetData"`
  23. SheetCalcPr *xlsxInnerXML `xml:"sheetCalcPr"`
  24. SheetProtection *xlsxSheetProtection `xml:"sheetProtection"`
  25. ProtectedRanges *xlsxInnerXML `xml:"protectedRanges"`
  26. Scenarios *xlsxInnerXML `xml:"scenarios"`
  27. AutoFilter *xlsxAutoFilter `xml:"autoFilter"`
  28. SortState *xlsxSortState `xml:"sortState"`
  29. DataConsolidate *xlsxInnerXML `xml:"dataConsolidate"`
  30. CustomSheetViews *xlsxCustomSheetViews `xml:"customSheetViews"`
  31. MergeCells *xlsxMergeCells `xml:"mergeCells"`
  32. PhoneticPr *xlsxPhoneticPr `xml:"phoneticPr"`
  33. ConditionalFormatting []*xlsxConditionalFormatting `xml:"conditionalFormatting"`
  34. DataValidations *xlsxDataValidations `xml:"dataValidations"`
  35. Hyperlinks *xlsxHyperlinks `xml:"hyperlinks"`
  36. PrintOptions *xlsxPrintOptions `xml:"printOptions"`
  37. PageMargins *xlsxPageMargins `xml:"pageMargins"`
  38. PageSetUp *xlsxPageSetUp `xml:"pageSetup"`
  39. HeaderFooter *xlsxHeaderFooter `xml:"headerFooter"`
  40. RowBreaks *xlsxBreaks `xml:"rowBreaks"`
  41. ColBreaks *xlsxBreaks `xml:"colBreaks"`
  42. CustomProperties *xlsxInnerXML `xml:"customProperties"`
  43. CellWatches *xlsxInnerXML `xml:"cellWatches"`
  44. IgnoredErrors *xlsxInnerXML `xml:"ignoredErrors"`
  45. SmartTags *xlsxInnerXML `xml:"smartTags"`
  46. Drawing *xlsxDrawing `xml:"drawing"`
  47. LegacyDrawing *xlsxLegacyDrawing `xml:"legacyDrawing"`
  48. LegacyDrawingHF *xlsxLegacyDrawingHF `xml:"legacyDrawingHF"`
  49. DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
  50. Picture *xlsxPicture `xml:"picture"`
  51. OleObjects *xlsxInnerXML `xml:"oleObjects"`
  52. Controls *xlsxInnerXML `xml:"controls"`
  53. WebPublishItems *xlsxInnerXML `xml:"webPublishItems"`
  54. TableParts *xlsxTableParts `xml:"tableParts"`
  55. ExtLst *xlsxExtLst `xml:"extLst"`
  56. }
  57. // xlsxDrawing change r:id to rid in the namespace.
  58. type xlsxDrawing struct {
  59. XMLName xml.Name `xml:"drawing"`
  60. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  61. }
  62. // xlsxHeaderFooter directly maps the headerFooter element in the namespace
  63. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - When printed or
  64. // viewed in page layout view (§18.18.69), each page of a worksheet can have a
  65. // page header, a page footer, or both. The headers and footers on odd-numbered
  66. // pages can differ from those on even-numbered pages, and the headers and
  67. // footers on the first page can differ from those on odd- and even-numbered
  68. // pages. In the latter case, the first page is not considered an odd page.
  69. type xlsxHeaderFooter struct {
  70. XMLName xml.Name `xml:"headerFooter"`
  71. AlignWithMargins bool `xml:"alignWithMargins,attr,omitempty"`
  72. DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
  73. DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
  74. ScaleWithDoc bool `xml:"scaleWithDoc,attr,omitempty"`
  75. OddHeader string `xml:"oddHeader,omitempty"`
  76. OddFooter string `xml:"oddFooter,omitempty"`
  77. EvenHeader string `xml:"evenHeader,omitempty"`
  78. EvenFooter string `xml:"evenFooter,omitempty"`
  79. FirstFooter string `xml:"firstFooter,omitempty"`
  80. FirstHeader string `xml:"firstHeader,omitempty"`
  81. DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
  82. }
  83. // xlsxDrawingHF (Drawing Reference in Header Footer) specifies the usage of
  84. // drawing objects to be rendered in the headers and footers of the sheet. It
  85. // specifies an explicit relationship to the part containing the DrawingML
  86. // shapes used in the headers and footers. It also indicates where in the
  87. // headers and footers each shape belongs. One drawing object can appear in
  88. // each of the left section, center section and right section of a header and
  89. // a footer.
  90. type xlsxDrawingHF struct {
  91. Content string `xml:",innerxml"`
  92. }
  93. // xlsxPageSetUp directly maps the pageSetup element in the namespace
  94. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
  95. // settings for the worksheet.
  96. type xlsxPageSetUp struct {
  97. XMLName xml.Name `xml:"pageSetup"`
  98. BlackAndWhite bool `xml:"blackAndWhite,attr,omitempty"`
  99. CellComments string `xml:"cellComments,attr,omitempty"`
  100. Copies int `xml:"copies,attr,omitempty"`
  101. Draft bool `xml:"draft,attr,omitempty"`
  102. Errors string `xml:"errors,attr,omitempty"`
  103. FirstPageNumber int `xml:"firstPageNumber,attr,omitempty"`
  104. FitToHeight int `xml:"fitToHeight,attr,omitempty"`
  105. FitToWidth int `xml:"fitToWidth,attr,omitempty"`
  106. HorizontalDPI int `xml:"horizontalDpi,attr,omitempty"`
  107. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  108. Orientation string `xml:"orientation,attr,omitempty"`
  109. PageOrder string `xml:"pageOrder,attr,omitempty"`
  110. PaperHeight string `xml:"paperHeight,attr,omitempty"`
  111. PaperSize int `xml:"paperSize,attr,omitempty"`
  112. PaperWidth string `xml:"paperWidth,attr,omitempty"`
  113. Scale int `xml:"scale,attr,omitempty"`
  114. UseFirstPageNumber bool `xml:"useFirstPageNumber,attr,omitempty"`
  115. UsePrinterDefaults bool `xml:"usePrinterDefaults,attr,omitempty"`
  116. VerticalDPI int `xml:"verticalDpi,attr,omitempty"`
  117. }
  118. // xlsxPrintOptions directly maps the printOptions element in the namespace
  119. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Print options for
  120. // the sheet. Printer-specific settings are stored separately in the Printer
  121. // Settings part.
  122. type xlsxPrintOptions struct {
  123. XMLName xml.Name `xml:"printOptions"`
  124. GridLines bool `xml:"gridLines,attr,omitempty"`
  125. GridLinesSet bool `xml:"gridLinesSet,attr,omitempty"`
  126. Headings bool `xml:"headings,attr,omitempty"`
  127. HorizontalCentered bool `xml:"horizontalCentered,attr,omitempty"`
  128. VerticalCentered bool `xml:"verticalCentered,attr,omitempty"`
  129. }
  130. // xlsxPageMargins directly maps the pageMargins element in the namespace
  131. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page margins for
  132. // a sheet or a custom sheet view.
  133. type xlsxPageMargins struct {
  134. XMLName xml.Name `xml:"pageMargins"`
  135. Bottom float64 `xml:"bottom,attr"`
  136. Footer float64 `xml:"footer,attr"`
  137. Header float64 `xml:"header,attr"`
  138. Left float64 `xml:"left,attr"`
  139. Right float64 `xml:"right,attr"`
  140. Top float64 `xml:"top,attr"`
  141. }
  142. // xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
  143. // http://schemas.openxmlformats.org/spreadsheetml/2006/main. This element
  144. // specifies the sheet formatting properties.
  145. type xlsxSheetFormatPr struct {
  146. XMLName xml.Name `xml:"sheetFormatPr"`
  147. BaseColWidth uint8 `xml:"baseColWidth,attr,omitempty"`
  148. DefaultColWidth float64 `xml:"defaultColWidth,attr,omitempty"`
  149. DefaultRowHeight float64 `xml:"defaultRowHeight,attr"`
  150. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  151. ZeroHeight bool `xml:"zeroHeight,attr,omitempty"`
  152. ThickTop bool `xml:"thickTop,attr,omitempty"`
  153. ThickBottom bool `xml:"thickBottom,attr,omitempty"`
  154. OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"`
  155. OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
  156. }
  157. // xlsxSheetViews represents worksheet views collection.
  158. type xlsxSheetViews struct {
  159. XMLName xml.Name `xml:"sheetViews"`
  160. SheetView []xlsxSheetView `xml:"sheetView"`
  161. }
  162. // xlsxSheetView represents a single sheet view definition. When more than one
  163. // sheet view is defined in the file, it means that when opening the workbook,
  164. // each sheet view corresponds to a separate window within the spreadsheet
  165. // application, where each window is showing the particular sheet containing
  166. // the same workbookViewId value, the last sheetView definition is loaded, and
  167. // the others are discarded. When multiple windows are viewing the same sheet,
  168. // multiple sheetView elements (with corresponding workbookView entries) are
  169. // saved.
  170. type xlsxSheetView struct {
  171. WindowProtection bool `xml:"windowProtection,attr,omitempty"`
  172. ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
  173. ShowGridLines *bool `xml:"showGridLines,attr"`
  174. ShowRowColHeaders *bool `xml:"showRowColHeaders,attr"`
  175. ShowZeros *bool `xml:"showZeros,attr,omitempty"`
  176. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  177. TabSelected bool `xml:"tabSelected,attr,omitempty"`
  178. ShowWhiteSpace *bool `xml:"showWhiteSpace,attr"`
  179. ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr,omitempty"`
  180. DefaultGridColor *bool `xml:"defaultGridColor,attr"`
  181. View string `xml:"view,attr,omitempty"`
  182. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  183. ColorID int `xml:"colorId,attr,omitempty"`
  184. ZoomScale float64 `xml:"zoomScale,attr,omitempty"`
  185. ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"`
  186. ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"`
  187. ZoomScaleSheetLayoutView float64 `xml:"zoomScaleSheetLayoutView,attr,omitempty"`
  188. WorkbookViewID int `xml:"workbookViewId,attr"`
  189. Pane *xlsxPane `xml:"pane,omitempty"`
  190. Selection []*xlsxSelection `xml:"selection"`
  191. }
  192. // xlsxSelection directly maps the selection element in the namespace
  193. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet view
  194. // selection.
  195. type xlsxSelection struct {
  196. ActiveCell string `xml:"activeCell,attr,omitempty"`
  197. ActiveCellID *int `xml:"activeCellId,attr"`
  198. Pane string `xml:"pane,attr,omitempty"`
  199. SQRef string `xml:"sqref,attr,omitempty"`
  200. }
  201. // xlsxSelection directly maps the selection element. Worksheet view pane.
  202. type xlsxPane struct {
  203. ActivePane string `xml:"activePane,attr,omitempty"`
  204. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  205. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  206. XSplit float64 `xml:"xSplit,attr,omitempty"`
  207. YSplit float64 `xml:"ySplit,attr,omitempty"`
  208. }
  209. // xlsxSheetPr directly maps the sheetPr element in the namespace
  210. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Sheet-level
  211. // properties.
  212. type xlsxSheetPr struct {
  213. XMLName xml.Name `xml:"sheetPr"`
  214. SyncHorizontal bool `xml:"syncHorizontal,attr,omitempty"`
  215. SyncVertical bool `xml:"syncVertical,attr,omitempty"`
  216. SyncRef string `xml:"syncRef,attr,omitempty"`
  217. TransitionEvaluation bool `xml:"transitionEvaluation,attr,omitempty"`
  218. Published *bool `xml:"published,attr"`
  219. CodeName string `xml:"codeName,attr,omitempty"`
  220. FilterMode bool `xml:"filterMode,attr,omitempty"`
  221. EnableFormatConditionsCalculation *bool `xml:"enableFormatConditionsCalculation,attr"`
  222. TransitionEntry bool `xml:"transitionEntry,attr,omitempty"`
  223. TabColor *xlsxTabColor `xml:"tabColor,omitempty"`
  224. OutlinePr *xlsxOutlinePr `xml:"outlinePr,omitempty"`
  225. PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
  226. }
  227. // xlsxOutlinePr maps to the outlinePr element. SummaryBelow allows you to
  228. // adjust the direction of grouper controls.
  229. type xlsxOutlinePr struct {
  230. SummaryBelow bool `xml:"summaryBelow,attr"`
  231. }
  232. // xlsxPageSetUpPr expresses page setup properties of the worksheet.
  233. type xlsxPageSetUpPr struct {
  234. AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"`
  235. FitToPage bool `xml:"fitToPage,attr,omitempty"`
  236. }
  237. // xlsxTabColor represents background color of the sheet tab.
  238. type xlsxTabColor struct {
  239. RGB string `xml:"rgb,attr,omitempty"`
  240. Theme int `xml:"theme,attr,omitempty"`
  241. Tint float64 `xml:"tint,attr,omitempty"`
  242. }
  243. // xlsxCols defines column width and column formatting for one or more columns
  244. // of the worksheet.
  245. type xlsxCols struct {
  246. XMLName xml.Name `xml:"cols"`
  247. Col []xlsxCol `xml:"col"`
  248. }
  249. // xlsxCol directly maps the col (Column Width & Formatting). Defines column
  250. // width and column formatting for one or more columns of the worksheet.
  251. type xlsxCol struct {
  252. BestFit bool `xml:"bestFit,attr,omitempty"`
  253. Collapsed bool `xml:"collapsed,attr,omitempty"`
  254. CustomWidth bool `xml:"customWidth,attr,omitempty"`
  255. Hidden bool `xml:"hidden,attr,omitempty"`
  256. Max int `xml:"max,attr"`
  257. Min int `xml:"min,attr"`
  258. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  259. Phonetic bool `xml:"phonetic,attr,omitempty"`
  260. Style int `xml:"style,attr,omitempty"`
  261. Width float64 `xml:"width,attr,omitempty"`
  262. }
  263. // xlsxDimension directly maps the dimension element in the namespace
  264. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element
  265. // specifies the used range of the worksheet. It specifies the row and column
  266. // bounds of used cells in the worksheet. This is optional and is not
  267. // required. Used cells include cells with formulas, text content, and cell
  268. // formatting. When an entire column is formatted, only the first cell in that
  269. // column is considered used.
  270. type xlsxDimension struct {
  271. XMLName xml.Name `xml:"dimension"`
  272. Ref string `xml:"ref,attr"`
  273. }
  274. // xlsxSheetData collection represents the cell table itself. This collection
  275. // expresses information about each cell, grouped together by rows in the
  276. // worksheet.
  277. type xlsxSheetData struct {
  278. XMLName xml.Name `xml:"sheetData"`
  279. Row []xlsxRow `xml:"row"`
  280. }
  281. // xlsxRow directly maps the row element. The element expresses information
  282. // about an entire row of a worksheet, and contains all cell definitions for a
  283. // particular row in the worksheet.
  284. type xlsxRow struct {
  285. Collapsed bool `xml:"collapsed,attr,omitempty"`
  286. CustomFormat bool `xml:"customFormat,attr,omitempty"`
  287. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  288. Hidden bool `xml:"hidden,attr,omitempty"`
  289. Ht float64 `xml:"ht,attr,omitempty"`
  290. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  291. Ph bool `xml:"ph,attr,omitempty"`
  292. R int `xml:"r,attr,omitempty"`
  293. S int `xml:"s,attr,omitempty"`
  294. Spans string `xml:"spans,attr,omitempty"`
  295. ThickBot bool `xml:"thickBot,attr,omitempty"`
  296. ThickTop bool `xml:"thickTop,attr,omitempty"`
  297. C []xlsxC `xml:"c"`
  298. }
  299. // xlsxSortState directly maps the sortState element. This collection
  300. // preserves the AutoFilter sort state.
  301. type xlsxSortState struct {
  302. ColumnSort bool `xml:"columnSort,attr,omitempty"`
  303. CaseSensitive bool `xml:"caseSensitive,attr,omitempty"`
  304. SortMethod string `xml:"sortMethod,attr,omitempty"`
  305. Ref string `xml:"ref,attr"`
  306. Content string `xml:",innerxml"`
  307. }
  308. // xlsxCustomSheetViews directly maps the customSheetViews element. This is a
  309. // collection of custom sheet views.
  310. type xlsxCustomSheetViews struct {
  311. XMLName xml.Name `xml:"customSheetViews"`
  312. CustomSheetView []*xlsxCustomSheetView `xml:"customSheetView"`
  313. }
  314. // xlsxBrk directly maps the row or column break to use when paginating a
  315. // worksheet.
  316. type xlsxBrk struct {
  317. ID int `xml:"id,attr,omitempty"`
  318. Min int `xml:"min,attr,omitempty"`
  319. Max int `xml:"max,attr,omitempty"`
  320. Man bool `xml:"man,attr,omitempty"`
  321. Pt bool `xml:"pt,attr,omitempty"`
  322. }
  323. // xlsxBreaks directly maps a collection of the row or column breaks.
  324. type xlsxBreaks struct {
  325. Brk []*xlsxBrk `xml:"brk"`
  326. Count int `xml:"count,attr,omitempty"`
  327. ManualBreakCount int `xml:"manualBreakCount,attr,omitempty"`
  328. }
  329. // xlsxCustomSheetView directly maps the customSheetView element.
  330. type xlsxCustomSheetView struct {
  331. Pane *xlsxPane `xml:"pane"`
  332. Selection *xlsxSelection `xml:"selection"`
  333. RowBreaks *xlsxBreaks `xml:"rowBreaks"`
  334. ColBreaks *xlsxBreaks `xml:"colBreaks"`
  335. PageMargins *xlsxPageMargins `xml:"pageMargins"`
  336. PrintOptions *xlsxPrintOptions `xml:"printOptions"`
  337. PageSetup *xlsxPageSetUp `xml:"pageSetup"`
  338. HeaderFooter *xlsxHeaderFooter `xml:"headerFooter"`
  339. AutoFilter *xlsxAutoFilter `xml:"autoFilter"`
  340. ExtLst *xlsxExtLst `xml:"extLst"`
  341. GUID string `xml:"guid,attr"`
  342. Scale int `xml:"scale,attr,omitempty"`
  343. ColorID int `xml:"colorId,attr,omitempty"`
  344. ShowPageBreaks bool `xml:"showPageBreaks,attr,omitempty"`
  345. ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
  346. ShowGridLines bool `xml:"showGridLines,attr,omitempty"`
  347. ShowRowCol bool `xml:"showRowCol,attr,omitempty"`
  348. OutlineSymbols bool `xml:"outlineSymbols,attr,omitempty"`
  349. ZeroValues bool `xml:"zeroValues,attr,omitempty"`
  350. FitToPage bool `xml:"fitToPage,attr,omitempty"`
  351. PrintArea bool `xml:"printArea,attr,omitempty"`
  352. Filter bool `xml:"filter,attr,omitempty"`
  353. ShowAutoFilter bool `xml:"showAutoFilter,attr,omitempty"`
  354. HiddenRows bool `xml:"hiddenRows,attr,omitempty"`
  355. HiddenColumns bool `xml:"hiddenColumns,attr,omitempty"`
  356. State string `xml:"state,attr,omitempty"`
  357. FilterUnique bool `xml:"filterUnique,attr,omitempty"`
  358. View string `xml:"view,attr,omitempty"`
  359. ShowRuler bool `xml:"showRuler,attr,omitempty"`
  360. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  361. }
  362. // xlsxMergeCell directly maps the mergeCell element. A single merged cell.
  363. type xlsxMergeCell struct {
  364. Ref string `xml:"ref,attr,omitempty"`
  365. }
  366. // xlsxMergeCells directly maps the mergeCells element. This collection
  367. // expresses all the merged cells in the sheet.
  368. type xlsxMergeCells struct {
  369. XMLName xml.Name `xml:"mergeCells"`
  370. Count int `xml:"count,attr,omitempty"`
  371. Cells []*xlsxMergeCell `xml:"mergeCell,omitempty"`
  372. }
  373. // xlsxDataValidations expresses all data validation information for cells in a
  374. // sheet which have data validation features applied.
  375. type xlsxDataValidations struct {
  376. XMLName xml.Name `xml:"dataValidations"`
  377. Count int `xml:"count,attr,omitempty"`
  378. DisablePrompts bool `xml:"disablePrompts,attr,omitempty"`
  379. XWindow int `xml:"xWindow,attr,omitempty"`
  380. YWindow int `xml:"yWindow,attr,omitempty"`
  381. DataValidation []*DataValidation `xml:"dataValidation"`
  382. }
  383. // DataValidation directly maps the a single item of data validation defined
  384. // on a range of the worksheet.
  385. type DataValidation struct {
  386. AllowBlank bool `xml:"allowBlank,attr"`
  387. Error *string `xml:"error,attr"`
  388. ErrorStyle *string `xml:"errorStyle,attr"`
  389. ErrorTitle *string `xml:"errorTitle,attr"`
  390. Operator string `xml:"operator,attr,omitempty"`
  391. Prompt *string `xml:"prompt,attr"`
  392. PromptTitle *string `xml:"promptTitle,attr"`
  393. ShowDropDown bool `xml:"showDropDown,attr,omitempty"`
  394. ShowErrorMessage bool `xml:"showErrorMessage,attr,omitempty"`
  395. ShowInputMessage bool `xml:"showInputMessage,attr,omitempty"`
  396. Sqref string `xml:"sqref,attr"`
  397. Type string `xml:"type,attr,omitempty"`
  398. Formula1 string `xml:",innerxml"`
  399. Formula2 string `xml:",innerxml"`
  400. }
  401. // xlsxC collection represents a cell in the worksheet. Information about the
  402. // cell's location (reference), value, data type, formatting, and formula is
  403. // expressed here.
  404. //
  405. // This simple type is restricted to the values listed in the following table:
  406. //
  407. // Enumeration Value | Description
  408. // ---------------------------+---------------------------------
  409. // b (Boolean) | Cell containing a boolean.
  410. // d (Date) | Cell contains a date in the ISO 8601 format.
  411. // e (Error) | Cell containing an error.
  412. // 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).
  413. // n (Number) | Cell containing a number.
  414. // s (Shared String) | Cell containing a shared string.
  415. // str (String) | Cell containing a formula string.
  416. //
  417. type xlsxC struct {
  418. XMLName xml.Name `xml:"c"`
  419. XMLSpace xml.Attr `xml:"space,attr,omitempty"`
  420. R string `xml:"r,attr,omitempty"` // Cell ID, e.g. A1
  421. S int `xml:"s,attr,omitempty"` // Style reference.
  422. // Str string `xml:"str,attr,omitempty"` // Style reference.
  423. T string `xml:"t,attr,omitempty"` // Type.
  424. F *xlsxF `xml:"f,omitempty"` // Formula
  425. V string `xml:"v,omitempty"` // Value
  426. IS *xlsxSI `xml:"is"`
  427. }
  428. func (c *xlsxC) hasValue() bool {
  429. return c.S != 0 || c.V != "" || c.F != nil || c.T != ""
  430. }
  431. // xlsxF represents a formula for the cell. The formula expression is
  432. // contained in the character node of this element.
  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. // xlsxLegacyDrawingHF specifies the explicit relationship to the part
  620. // containing the VML defining pictures rendered in the header / footer of the
  621. // sheet.
  622. type xlsxLegacyDrawingHF struct {
  623. XMLName xml.Name `xml:"legacyDrawingHF"`
  624. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  625. }
  626. type xlsxInnerXML struct {
  627. Content string `xml:",innerxml"`
  628. }
  629. // xlsxWorksheetExt directly maps the ext element in the worksheet.
  630. type xlsxWorksheetExt struct {
  631. XMLName xml.Name `xml:"ext"`
  632. URI string `xml:"uri,attr"`
  633. Content string `xml:",innerxml"`
  634. }
  635. // decodeWorksheetExt directly maps the ext element.
  636. type decodeWorksheetExt struct {
  637. XMLName xml.Name `xml:"extLst"`
  638. Ext []*xlsxWorksheetExt `xml:"ext"`
  639. }
  640. // decodeX14SparklineGroups directly maps the sparklineGroups element.
  641. type decodeX14SparklineGroups struct {
  642. XMLName xml.Name `xml:"sparklineGroups"`
  643. XMLNSXM string `xml:"xmlns:xm,attr"`
  644. Content string `xml:",innerxml"`
  645. }
  646. // xlsxX14SparklineGroups directly maps the sparklineGroups element.
  647. type xlsxX14SparklineGroups struct {
  648. XMLName xml.Name `xml:"x14:sparklineGroups"`
  649. XMLNSXM string `xml:"xmlns:xm,attr"`
  650. SparklineGroups []*xlsxX14SparklineGroup `xml:"x14:sparklineGroup"`
  651. Content string `xml:",innerxml"`
  652. }
  653. // xlsxX14SparklineGroup directly maps the sparklineGroup element.
  654. type xlsxX14SparklineGroup struct {
  655. XMLName xml.Name `xml:"x14:sparklineGroup"`
  656. ManualMax int `xml:"manualMax,attr,omitempty"`
  657. ManualMin int `xml:"manualMin,attr,omitempty"`
  658. LineWeight float64 `xml:"lineWeight,attr,omitempty"`
  659. Type string `xml:"type,attr,omitempty"`
  660. DateAxis bool `xml:"dateAxis,attr,omitempty"`
  661. DisplayEmptyCellsAs string `xml:"displayEmptyCellsAs,attr,omitempty"`
  662. Markers bool `xml:"markers,attr,omitempty"`
  663. High bool `xml:"high,attr,omitempty"`
  664. Low bool `xml:"low,attr,omitempty"`
  665. First bool `xml:"first,attr,omitempty"`
  666. Last bool `xml:"last,attr,omitempty"`
  667. Negative bool `xml:"negative,attr,omitempty"`
  668. DisplayXAxis bool `xml:"displayXAxis,attr,omitempty"`
  669. DisplayHidden bool `xml:"displayHidden,attr,omitempty"`
  670. MinAxisType string `xml:"minAxisType,attr,omitempty"`
  671. MaxAxisType string `xml:"maxAxisType,attr,omitempty"`
  672. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  673. ColorSeries *xlsxTabColor `xml:"x14:colorSeries"`
  674. ColorNegative *xlsxTabColor `xml:"x14:colorNegative"`
  675. ColorAxis *xlsxColor `xml:"x14:colorAxis"`
  676. ColorMarkers *xlsxTabColor `xml:"x14:colorMarkers"`
  677. ColorFirst *xlsxTabColor `xml:"x14:colorFirst"`
  678. ColorLast *xlsxTabColor `xml:"x14:colorLast"`
  679. ColorHigh *xlsxTabColor `xml:"x14:colorHigh"`
  680. ColorLow *xlsxTabColor `xml:"x14:colorLow"`
  681. Sparklines xlsxX14Sparklines `xml:"x14:sparklines"`
  682. }
  683. // xlsxX14Sparklines directly maps the sparklines element.
  684. type xlsxX14Sparklines struct {
  685. Sparkline []*xlsxX14Sparkline `xml:"x14:sparkline"`
  686. }
  687. // xlsxX14Sparkline directly maps the sparkline element.
  688. type xlsxX14Sparkline struct {
  689. F string `xml:"xm:f"`
  690. Sqref string `xml:"xm:sqref"`
  691. }
  692. // SparklineOption directly maps the settings of the sparkline.
  693. type SparklineOption struct {
  694. Location []string
  695. Range []string
  696. Max int
  697. CustMax int
  698. Min int
  699. CustMin int
  700. Type string
  701. Weight float64
  702. DateAxis bool
  703. Markers bool
  704. High bool
  705. Low bool
  706. First bool
  707. Last bool
  708. Negative bool
  709. Axis bool
  710. Hidden bool
  711. Reverse bool
  712. Style int
  713. SeriesColor string
  714. NegativeColor string
  715. MarkersColor string
  716. FirstColor string
  717. LastColor string
  718. HightColor string
  719. LowColor string
  720. EmptyCells string
  721. }
  722. // formatPanes directly maps the settings of the panes.
  723. type formatPanes struct {
  724. Freeze bool `json:"freeze"`
  725. Split bool `json:"split"`
  726. XSplit int `json:"x_split"`
  727. YSplit int `json:"y_split"`
  728. TopLeftCell string `json:"top_left_cell"`
  729. ActivePane string `json:"active_pane"`
  730. Panes []struct {
  731. SQRef string `json:"sqref"`
  732. ActiveCell string `json:"active_cell"`
  733. Pane string `json:"pane"`
  734. } `json:"panes"`
  735. }
  736. // formatConditional directly maps the conditional format settings of the cells.
  737. type formatConditional struct {
  738. Type string `json:"type"`
  739. AboveAverage bool `json:"above_average"`
  740. Percent bool `json:"percent"`
  741. Format int `json:"format"`
  742. Criteria string `json:"criteria"`
  743. Value string `json:"value,omitempty"`
  744. Minimum string `json:"minimum,omitempty"`
  745. Maximum string `json:"maximum,omitempty"`
  746. MinType string `json:"min_type,omitempty"`
  747. MidType string `json:"mid_type,omitempty"`
  748. MaxType string `json:"max_type,omitempty"`
  749. MinValue string `json:"min_value,omitempty"`
  750. MidValue string `json:"mid_value,omitempty"`
  751. MaxValue string `json:"max_value,omitempty"`
  752. MinColor string `json:"min_color,omitempty"`
  753. MidColor string `json:"mid_color,omitempty"`
  754. MaxColor string `json:"max_color,omitempty"`
  755. MinLength string `json:"min_length,omitempty"`
  756. MaxLength string `json:"max_length,omitempty"`
  757. MultiRange string `json:"multi_range,omitempty"`
  758. BarColor string `json:"bar_color,omitempty"`
  759. }
  760. // FormatSheetProtection directly maps the settings of worksheet protection.
  761. type FormatSheetProtection struct {
  762. AutoFilter bool
  763. DeleteColumns bool
  764. DeleteRows bool
  765. EditObjects bool
  766. EditScenarios bool
  767. FormatCells bool
  768. FormatColumns bool
  769. FormatRows bool
  770. InsertColumns bool
  771. InsertHyperlinks bool
  772. InsertRows bool
  773. Password string
  774. PivotTables bool
  775. SelectLockedCells bool
  776. SelectUnlockedCells bool
  777. Sort bool
  778. }
  779. // FormatHeaderFooter directly maps the settings of header and footer.
  780. type FormatHeaderFooter struct {
  781. AlignWithMargins bool
  782. DifferentFirst bool
  783. DifferentOddEven bool
  784. ScaleWithDoc bool
  785. OddHeader string
  786. OddFooter string
  787. EvenHeader string
  788. EvenFooter string
  789. FirstFooter string
  790. FirstHeader string
  791. }
  792. // FormatPageMargins directly maps the settings of page margins
  793. type FormatPageMargins struct {
  794. Bottom string
  795. Footer string
  796. Header string
  797. Left string
  798. Right string
  799. Top string
  800. }