xmlWorksheet.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // Some code of this file reference tealeg/xlsx.
  2. package excelize
  3. import "encoding/xml"
  4. // xlsxWorksheet directly maps the worksheet element in the namespace
  5. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  6. // currently I have not checked it for completeness - it does as much
  7. // as I need.
  8. type xlsxWorksheet struct {
  9. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
  10. SheetPr xlsxSheetPr `xml:"sheetPr"`
  11. Dimension xlsxDimension `xml:"dimension"`
  12. SheetViews xlsxSheetViews `xml:"sheetViews"`
  13. SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
  14. Cols *xlsxCols `xml:"cols,omitempty"`
  15. SheetData xlsxSheetData `xml:"sheetData"`
  16. SheetProtection xlsxSheetProtection `xml:"sheetProtection"`
  17. MergeCells *xlsxMergeCells `xml:"mergeCells,omitempty"`
  18. ConditionalFormatting xlsxConditionalFormatting `xml:"conditionalFormatting"`
  19. Hyperlinks xlsxHyperlinks `xml:"hyperlinks"`
  20. PrintOptions xlsxPrintOptions `xml:"printOptions"`
  21. PageMargins xlsxPageMargins `xml:"pageMargins"`
  22. PageSetUp xlsxPageSetUp `xml:"pageSetup"`
  23. HeaderFooter xlsxHeaderFooter `xml:"headerFooter"`
  24. Drawing xlsxDrawing `xml:"drawing"`
  25. LegacyDrawing xlsxLegacyDrawing `xml:"legacyDrawing"`
  26. Picture xlsxPicture `xml:"picture"`
  27. TableParts xlsxTableParts `xml:"tableParts"`
  28. ExtLst xlsxExtLst `xml:"extLst"`
  29. }
  30. // xlsxDrawing change r:id to rid in the namespace.
  31. type xlsxDrawing struct {
  32. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  33. }
  34. // xlsxHeaderFooter directly maps the headerFooter element in the namespace
  35. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  36. // currently I have not checked it for completeness - it does as much
  37. // as I need.
  38. type xlsxHeaderFooter struct {
  39. DifferentFirst bool `xml:"differentFirst,attr"`
  40. DifferentOddEven bool `xml:"differentOddEven,attr"`
  41. OddHeader []xlsxOddHeader `xml:"oddHeader"`
  42. OddFooter []xlsxOddFooter `xml:"oddFooter"`
  43. }
  44. // xlsxOddHeader directly maps the oddHeader element in the namespace
  45. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  46. // currently I have not checked it for completeness - it does as much
  47. // as I need.
  48. type xlsxOddHeader struct {
  49. Content string `xml:",chardata"`
  50. }
  51. // xlsxOddFooter directly maps the oddFooter element in the namespace
  52. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  53. // currently I have not checked it for completeness - it does as much
  54. // as I need.
  55. type xlsxOddFooter struct {
  56. Content string `xml:",chardata"`
  57. }
  58. // xlsxPageSetUp directly maps the pageSetup element in the namespace
  59. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  60. // currently I have not checked it for completeness - it does as much
  61. // as I need.
  62. type xlsxPageSetUp struct {
  63. PaperSize string `xml:"paperSize,attr,omitempty"`
  64. Scale int `xml:"scale,attr"`
  65. FirstPageNumber int `xml:"firstPageNumber,attr"`
  66. FitToWidth int `xml:"fitToWidth,attr"`
  67. FitToHeight int `xml:"fitToHeight,attr"`
  68. PageOrder string `xml:"pageOrder,attr,omitempty"`
  69. Orientation string `xml:"orientation,attr,omitempty"`
  70. UsePrinterDefaults bool `xml:"usePrinterDefaults,attr"`
  71. BlackAndWhite bool `xml:"blackAndWhite,attr"`
  72. Draft bool `xml:"draft,attr"`
  73. CellComments string `xml:"cellComments,attr,omitempty"`
  74. UseFirstPageNumber bool `xml:"useFirstPageNumber,attr"`
  75. HorizontalDPI float32 `xml:"horizontalDpi,attr"`
  76. VerticalDPI float32 `xml:"verticalDpi,attr"`
  77. Copies int `xml:"copies,attr"`
  78. }
  79. // xlsxPrintOptions directly maps the printOptions element in the namespace
  80. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  81. // currently I have not checked it for completeness - it does as much
  82. // as I need.
  83. type xlsxPrintOptions struct {
  84. Headings bool `xml:"headings,attr"`
  85. GridLines bool `xml:"gridLines,attr"`
  86. GridLinesSet bool `xml:"gridLinesSet,attr"`
  87. HorizontalCentered bool `xml:"horizontalCentered,attr"`
  88. VerticalCentered bool `xml:"verticalCentered,attr"`
  89. }
  90. // xlsxPageMargins directly maps the pageMargins element in the namespace
  91. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  92. // currently I have not checked it for completeness - it does as much
  93. // as I need.
  94. type xlsxPageMargins struct {
  95. Left float64 `xml:"left,attr"`
  96. Right float64 `xml:"right,attr"`
  97. Top float64 `xml:"top,attr"`
  98. Bottom float64 `xml:"bottom,attr"`
  99. Header float64 `xml:"header,attr"`
  100. Footer float64 `xml:"footer,attr"`
  101. }
  102. // xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
  103. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  104. // currently I have not checked it for completeness - it does as much
  105. // as I need.
  106. type xlsxSheetFormatPr struct {
  107. DefaultColWidth float64 `xml:"defaultColWidth,attr,omitempty"`
  108. DefaultRowHeight float64 `xml:"defaultRowHeight,attr"`
  109. CustomHeight float64 `xml:"customHeight,attr,omitempty"`
  110. ZeroHeight float64 `xml:"zeroHeight,attr,omitempty"`
  111. OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
  112. OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"`
  113. }
  114. // xlsxSheetViews directly maps the sheetViews element in the namespace
  115. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  116. // currently I have not checked it for completeness - it does as much
  117. // as I need.
  118. type xlsxSheetViews struct {
  119. SheetView []xlsxSheetView `xml:"sheetView"`
  120. }
  121. // xlsxSheetView directly maps the sheetView element in the namespace
  122. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  123. // currently I have not checked it for completeness - it does as much
  124. // as I need.
  125. //
  126. // A single sheet view definition. When more than one sheet view is
  127. // defined in the file, it means that when opening the workbook, each
  128. // sheet view corresponds to a separate window within the spreadsheet
  129. // application, where each window is showing the particular sheet
  130. // containing the same workbookViewId value, the last sheetView
  131. // definition is loaded, and the others are discarded. When multiple
  132. // windows are viewing the same sheet, multiple sheetView elements
  133. // (with corresponding workbookView entries) are saved.
  134. type xlsxSheetView struct {
  135. WindowProtection bool `xml:"windowProtection,attr,omitempty"`
  136. ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
  137. ShowGridLines string `xml:"showGridLines,attr,omitempty"`
  138. ShowRowColHeaders bool `xml:"showRowColHeaders,attr,omitempty"`
  139. ShowZeros bool `xml:"showZeros,attr,omitempty"`
  140. RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
  141. TabSelected bool `xml:"tabSelected,attr,omitempty"`
  142. ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr,omitempty"`
  143. DefaultGridColor bool `xml:"defaultGridColor,attr"`
  144. View string `xml:"view,attr,omitempty"`
  145. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  146. ColorId int `xml:"colorId,attr,omitempty"`
  147. ZoomScale float64 `xml:"zoomScale,attr,omitempty"`
  148. ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"`
  149. ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"`
  150. WorkbookViewID int `xml:"workbookViewId,attr"`
  151. Pane *xlsxPane `xml:"pane,omitempty"`
  152. Selection []xlsxSelection `xml:"selection"`
  153. }
  154. // xlsxSelection directly maps the selection element in the namespace
  155. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  156. // currently I have not checked it for completeness - it does as much
  157. // as I need.
  158. type xlsxSelection struct {
  159. Pane string `xml:"pane,attr,omitempty"`
  160. ActiveCell string `xml:"activeCell,attr,omitempty"`
  161. ActiveCellID int `xml:"activeCellId,attr"`
  162. SQRef string `xml:"sqref,attr,omitempty"`
  163. }
  164. // xlsxSelection directly maps the selection element in the namespace
  165. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  166. // currently I have not checked it for completeness - it does as much
  167. // as I need.
  168. type xlsxPane struct {
  169. XSplit float64 `xml:"xSplit,attr"`
  170. YSplit float64 `xml:"ySplit,attr"`
  171. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  172. ActivePane string `xml:"activePane,attr,omitempty"`
  173. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  174. }
  175. // xlsxSheetPr directly maps the sheetPr element in the namespace
  176. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  177. // currently I have not checked it for completeness - it does as much
  178. // as I need.
  179. type xlsxSheetPr struct {
  180. XMLName xml.Name `xml:"sheetPr"`
  181. FilterMode bool `xml:"filterMode,attr,omitempty"`
  182. CodeName string `xml:"codeName,attr,omitempty"`
  183. EnableFormatConditionsCalculation int `xml:"enableFormatConditionsCalculation,attr,omitempty"`
  184. TabColor xlsxTabColor `xml:"tabColor,omitempty"`
  185. PageSetUpPr xlsxPageSetUpPr `xml:"pageSetUpPr"`
  186. }
  187. // xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
  188. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  189. // currently I have not checked it for completeness - it does as much
  190. // as I need.
  191. type xlsxPageSetUpPr struct {
  192. FitToPage bool `xml:"fitToPage,attr"` // Flag indicating whether the Fit to Page print option is enabled.
  193. }
  194. // xlsxTabColor directly maps the tabColor element in the namespace
  195. // currently I have not checked it for completeness - it does as much
  196. // as I need.
  197. type xlsxTabColor struct {
  198. Theme int `xml:"theme,attr,omitempty"` // (Theme Color) A zero-based index into the <clrScheme> collection (§20.1.6.2), referencing a particular <sysClr> or <srgbClr> value expressed in the Theme part.
  199. Tint uint8 `xml:"tint,attr,omitempty"` // Specifies the tint value applied to the color.
  200. }
  201. // xlsxCols directly maps the cols element in the namespace
  202. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  203. // currently I have not checked it for completeness - it does as much
  204. // as I need.
  205. type xlsxCols struct {
  206. Col []xlsxCol `xml:"col"`
  207. }
  208. // xlsxCol directly maps the col element in the namespace
  209. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  210. // currently I have not checked it for completeness - it does as much
  211. // as I need.
  212. type xlsxCol struct {
  213. Collapsed bool `xml:"collapsed,attr"`
  214. Hidden bool `xml:"hidden,attr"`
  215. Max int `xml:"max,attr"`
  216. Min int `xml:"min,attr"`
  217. Style int `xml:"style,attr"`
  218. Width float64 `xml:"width,attr"`
  219. CustomWidth int `xml:"customWidth,attr,omitempty"`
  220. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  221. }
  222. // xlsxDimension directly maps the dimension element in the namespace
  223. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  224. // currently I have not checked it for completeness - it does as much
  225. // as I need.
  226. type xlsxDimension struct {
  227. Ref string `xml:"ref,attr"`
  228. }
  229. // xlsxSheetData directly maps the sheetData element in the namespace
  230. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  231. // currently I have not checked it for completeness - it does as much
  232. // as I need.
  233. type xlsxSheetData struct {
  234. XMLName xml.Name `xml:"sheetData"`
  235. Row []xlsxRow `xml:"row"`
  236. }
  237. // xlsxRow directly maps the row element in the namespace
  238. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  239. // currently I have not checked it for completeness - it does as much
  240. // as I need.
  241. type xlsxRow struct {
  242. R int `xml:"r,attr"`
  243. Spans string `xml:"spans,attr,omitempty"`
  244. Hidden bool `xml:"hidden,attr,omitempty"`
  245. C []xlsxC `xml:"c"`
  246. Ht string `xml:"ht,attr,omitempty"`
  247. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  248. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  249. }
  250. type xlsxMergeCell struct {
  251. Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both "D3:G4"
  252. }
  253. type xlsxMergeCells struct {
  254. XMLName xml.Name //`xml:"mergeCells,omitempty"`
  255. Count int `xml:"count,attr,omitempty"`
  256. Cells []xlsxMergeCell `xml:"mergeCell,omitempty"`
  257. }
  258. // xlsxC directly maps the c element in the namespace
  259. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  260. // currently I have not checked it for completeness - it does as much
  261. // as I need.
  262. type xlsxC struct {
  263. R string `xml:"r,attr"` // Cell ID, e.g. A1
  264. S int `xml:"s,attr,omitempty"` // Style reference.
  265. // Str string `xml:"str,attr,omitempty"` // Style reference.
  266. T string `xml:"t,attr,omitempty"` // Type.
  267. F *xlsxF `xml:"f,omitempty"` // Formula
  268. V string `xml:"v,omitempty"` // Value
  269. }
  270. // xlsxF directly maps the f element in the namespace
  271. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  272. // currently I have not checked it for completeness - it does as much
  273. // as I need.
  274. type xlsxF struct {
  275. Content string `xml:",chardata"`
  276. T string `xml:"t,attr,omitempty"` // Formula type
  277. Ref string `xml:"ref,attr,omitempty"` // Shared formula ref
  278. Si string `xml:"si,attr,omitempty"` // Shared formula index
  279. }
  280. // xlsxSheetProtection collection expresses the sheet protection options
  281. // to enforce when the sheet is protected.
  282. type xlsxSheetProtection struct {
  283. AlgorithmName string `xml:"algorithmName,attr,omitempty"`
  284. AutoFilter int `xml:"autoFilter,attr,omitempty"`
  285. DeleteColumns int `xml:"deleteColumns,attr,omitempty"`
  286. DeleteRows int `xml:"deleteRows,attr,omitempty"`
  287. FormatCells int `xml:"formatCells,attr,omitempty"`
  288. FormatColumns int `xml:"formatColumns,attr,omitempty"`
  289. FormatRows int `xml:"formatRows,attr,omitempty"`
  290. HashValue string `xml:"hashValue,attr,omitempty"`
  291. InsertColumns int `xml:"insertColumns,attr,omitempty"`
  292. InsertHyperlinks int `xml:"insertHyperlinks,attr,omitempty"`
  293. InsertRows int `xml:"insertRows,attr,omitempty"`
  294. Objects int `xml:"objects,attr,omitempty"`
  295. PivotTables int `xml:"pivotTables,attr,omitempty"`
  296. SaltValue string `xml:"saltValue,attr,omitempty"`
  297. Scenarios int `xml:"scenarios,attr,omitempty"`
  298. SelectLockedCells int `xml:"selectLockedCells,attr,omitempty"`
  299. SelectUnlockedCell int `xml:"selectUnlockedCell,attr,omitempty"`
  300. Sheet int `xml:"sheet,attr,omitempty"`
  301. Sort int `xml:"sort,attr,omitempty"`
  302. SpinCount int `xml:"spinCount,attr,omitempty"`
  303. }
  304. // A Conditional Format is a format, such as cell shading or font color,
  305. // that a spreadsheet application can automatically apply to cells if a
  306. // specified condition is true. This collection expresses conditional
  307. // formatting rules applied to a particular cell or range.
  308. type xlsxConditionalFormatting struct {
  309. CfRule string `xml:",innerxml"`
  310. }
  311. // xlsxHyperlinks directly maps the hyperlinks element in the namespace
  312. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  313. type xlsxHyperlinks struct {
  314. Hyperlink []xlsxHyperlink `xml:"hyperlink"`
  315. }
  316. // xlsxHyperlink directly maps the hyperlink element in the namespace
  317. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  318. type xlsxHyperlink struct {
  319. Ref string `xml:"ref,attr"`
  320. Location string `xml:"location,attr,omitempty"`
  321. Display string `xml:"display,attr,omitempty"`
  322. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  323. }
  324. // xlsxTableParts directly maps the tableParts element in the namespace
  325. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  326. // The table element has several attributes applied to identify the table
  327. // and the data range it covers. The table id attribute needs to be unique
  328. // across all table parts, the same goes for the name and displayName. The
  329. // displayName has the further restriction that it must be unique across
  330. // all defined names in the workbook. Later on we will see that you can
  331. // define names for many elements, such as cells or formulas. The name
  332. // value is used for the object model in Microsoft Office Excel. The
  333. // displayName is used for references in formulas. The ref attribute is
  334. // used to identify the cell range that the table covers. This includes
  335. // not only the table data, but also the table header containing column
  336. // names.
  337. // To add columns to your table you add new tableColumn elements to the
  338. // tableColumns container. Similar to the shared string table the
  339. // collection keeps a count attribute identifying the number of columns.
  340. // Besides the table definition in the table part there is also the need
  341. // to identify which tables are displayed in the worksheet. The worksheet
  342. // part has a separate element tableParts to store this information. Each
  343. // table part is referenced through the relationship ID and again a count
  344. // of the number of table parts is maintained. The following markup sample
  345. // is taken from the documents accompanying this book. The sheet data
  346. // element has been removed to reduce the size of the sample. To reference
  347. // the table, just add the tableParts element, of course after having
  348. // created and stored the table part.
  349. // Example:
  350. //
  351. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  352. // ...
  353. // <tableParts count="1">
  354. // <tablePart r:id="rId1" />
  355. // </tableParts>
  356. // </worksheet>
  357. //
  358. type xlsxTableParts struct {
  359. Count int `xml:"count,attr"`
  360. TableParts []xlsxTablePart `xml:"tablePart"`
  361. }
  362. // xlsxTablePart directly maps the tablePart element in the namespace
  363. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  364. type xlsxTablePart struct {
  365. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  366. }
  367. // xlsxPicture directly maps the picture element in the namespace
  368. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  369. // Background sheet image.
  370. // Example:
  371. //
  372. // <picture r:id="rId1"/>
  373. //
  374. type xlsxPicture struct {
  375. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` // Relationship Id pointing to the image part.
  376. }
  377. // xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace
  378. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  379. // A comment is a rich text note that is attached to, and associated with,
  380. // a cell, separate from other cell content. Comment content is stored
  381. // separate from the cell, and is displayed in a drawing object (like a
  382. // text box) that is separate from, but associated with, a cell. Comments
  383. // are used as reminders, such as noting how a complex formula works, or
  384. // to provide feedback to other users. Comments can also be used to explain
  385. // assumptions made in a formula or to call out something special about the cell.
  386. type xlsxLegacyDrawing struct {
  387. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  388. }