xmlWorksheet.go 17 KB

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