xmlWorksheet.go 17 KB

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