xmlWorksheet.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. type xlsxSheetView struct {
  123. // WindowProtection bool `xml:"windowProtection,attr"`
  124. // ShowFormulas bool `xml:"showFormulas,attr"`
  125. ShowGridLines string `xml:"showGridLines,attr,omitempty"`
  126. // ShowRowColHeaders bool `xml:"showRowColHeaders,attr"`
  127. // ShowZeros bool `xml:"showZeros,attr"`
  128. // RightToLeft bool `xml:"rightToLeft,attr"`
  129. TabSelected bool `xml:"tabSelected,attr"`
  130. // ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr"`
  131. // DefaultGridColor bool `xml:"defaultGridColor,attr"`
  132. // View string `xml:"view,attr"`
  133. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  134. // ColorId int `xml:"colorId,attr"`
  135. ZoomScale float64 `xml:"zoomScale,attr,omitempty"`
  136. ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"`
  137. ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"`
  138. WorkbookViewID int `xml:"workbookViewId,attr"`
  139. Selection []xlsxSelection `xml:"selection"`
  140. Pane *xlsxPane `xml:"pane,omitempty"`
  141. }
  142. // xlsxSelection directly maps the selection element in the namespace
  143. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  144. // currently I have not checked it for completeness - it does as much
  145. // as I need.
  146. type xlsxSelection struct {
  147. Pane string `xml:"pane,attr,omitempty"`
  148. ActiveCell string `xml:"activeCell,attr,omitempty"`
  149. ActiveCellID int `xml:"activeCellId,attr"`
  150. SQRef string `xml:"sqref,attr"`
  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 xlsxPane struct {
  157. XSplit float64 `xml:"xSplit,attr"`
  158. YSplit float64 `xml:"ySplit,attr"`
  159. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  160. ActivePane string `xml:"activePane,attr,omitempty"`
  161. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  162. }
  163. // xlsxSheetPr directly maps the sheetPr element in the namespace
  164. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  165. // currently I have not checked it for completeness - it does as much
  166. // as I need.
  167. type xlsxSheetPr struct {
  168. FilterMode bool `xml:"filterMode,attr"`
  169. PageSetUpPr []xlsxPageSetUpPr `xml:"pageSetUpPr"`
  170. }
  171. // xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
  172. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  173. // currently I have not checked it for completeness - it does as much
  174. // as I need.
  175. type xlsxPageSetUpPr struct {
  176. FitToPage bool `xml:"fitToPage,attr"`
  177. }
  178. // xlsxCols directly maps the cols element in the namespace
  179. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  180. // currently I have not checked it for completeness - it does as much
  181. // as I need.
  182. type xlsxCols struct {
  183. Col []xlsxCol `xml:"col"`
  184. }
  185. // xlsxCol directly maps the col 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 xlsxCol struct {
  190. Collapsed bool `xml:"collapsed,attr"`
  191. Hidden bool `xml:"hidden,attr"`
  192. Max int `xml:"max,attr"`
  193. Min int `xml:"min,attr"`
  194. Style int `xml:"style,attr"`
  195. Width float64 `xml:"width,attr"`
  196. CustomWidth int `xml:"customWidth,attr,omitempty"`
  197. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  198. }
  199. // xlsxDimension directly maps the dimension 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 xlsxDimension struct {
  204. Ref string `xml:"ref,attr"`
  205. }
  206. // xlsxSheetData directly maps the sheetData 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 xlsxSheetData struct {
  211. XMLName xml.Name `xml:"sheetData"`
  212. Row []xlsxRow `xml:"row"`
  213. }
  214. // xlsxRow directly maps the row element in the namespace
  215. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  216. // currently I have not checked it for completeness - it does as much
  217. // as I need.
  218. type xlsxRow struct {
  219. R int `xml:"r,attr"`
  220. Spans string `xml:"spans,attr,omitempty"`
  221. Hidden bool `xml:"hidden,attr,omitempty"`
  222. C []xlsxC `xml:"c"`
  223. Ht string `xml:"ht,attr,omitempty"`
  224. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  225. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  226. }
  227. type xlsxMergeCell struct {
  228. Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both "D3:G4"
  229. }
  230. type xlsxMergeCells struct {
  231. XMLName xml.Name //`xml:"mergeCells,omitempty"`
  232. Count int `xml:"count,attr,omitempty"`
  233. Cells []xlsxMergeCell `xml:"mergeCell,omitempty"`
  234. }
  235. // xlsxC directly maps the c 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 xlsxC struct {
  240. R string `xml:"r,attr"` // Cell ID, e.g. A1
  241. S int `xml:"s,attr,omitempty"` // Style reference.
  242. // Str string `xml:"str,attr,omitempty"` // Style reference.
  243. T string `xml:"t,attr,omitempty"` // Type.
  244. F *xlsxF `xml:"f,omitempty"` // Formula
  245. V string `xml:"v,omitempty"` // Value
  246. }
  247. // xlsxF directly maps the f element in the namespace
  248. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  249. // currently I have not checked it for completeness - it does as much
  250. // as I need.
  251. type xlsxF struct {
  252. Content string `xml:",chardata"`
  253. T string `xml:"t,attr,omitempty"` // Formula type
  254. Ref string `xml:"ref,attr,omitempty"` // Shared formula ref
  255. Si int `xml:"si,attr,omitempty"` // Shared formula index
  256. }
  257. // xlsxHyperlinks directly maps the hyperlinks element in the namespace
  258. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  259. type xlsxHyperlinks struct {
  260. Hyperlink []xlsxHyperlink `xml:"hyperlink"`
  261. }
  262. // xlsxHyperlink directly maps the hyperlink element in the namespace
  263. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  264. type xlsxHyperlink struct {
  265. Ref string `xml:"ref,attr"`
  266. Location string `xml:"location,attr,omitempty"`
  267. Display string `xml:"display,attr,omitempty"`
  268. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  269. }
  270. // xlsxTableParts directly maps the tableParts element in the namespace
  271. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  272. // The table element has several attributes applied to identify the table
  273. // and the data range it covers. The table id attribute needs to be unique
  274. // across all table parts, the same goes for the name and displayName. The
  275. // displayName has the further restriction that it must be unique across
  276. // all defined names in the workbook. Later on we will see that you can
  277. // define names for many elements, such as cells or formulas. The name
  278. // value is used for the object model in Microsoft Office Excel. The
  279. // displayName is used for references in formulas. The ref attribute is
  280. // used to identify the cell range that the table covers. This includes
  281. // not only the table data, but also the table header containing column
  282. // names.
  283. // To add columns to your table you add new tableColumn elements to the
  284. // tableColumns container. Similar to the shared string table the
  285. // collection keeps a count attribute identifying the number of columns.
  286. // Besides the table definition in the table part there is also the need
  287. // to identify which tables are displayed in the worksheet. The worksheet
  288. // part has a separate element tableParts to store this information. Each
  289. // table part is referenced through the relationship ID and again a count
  290. // of the number of table parts is maintained. The following markup sample
  291. // is taken from the documents accompanying this book. The sheet data
  292. // element has been removed to reduce the size of the sample. To reference
  293. // the table, just add the tableParts element, of course after having
  294. // created and stored the table part.
  295. // Example:
  296. //
  297. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  298. // ...
  299. // <tableParts count="1">
  300. // <tablePart r:id="rId1" />
  301. // </tableParts>
  302. // </worksheet>
  303. //
  304. type xlsxTableParts struct {
  305. Count int `xml:"count,attr"`
  306. TableParts []xlsxTablePart `xml:"tablePart"`
  307. }
  308. // xlsxTablePart directly maps the tablePart element in the namespace
  309. // http://schemas.openxmlformats.org/spreadsheetml/2006/main
  310. type xlsxTablePart struct {
  311. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  312. }
  313. // xlsxPicture directly maps the picture element in the namespace
  314. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  315. // Background sheet image.
  316. // Example:
  317. //
  318. // <picture r:id="rId1"/>
  319. //
  320. type xlsxPicture struct {
  321. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` // Relationship Id pointing to the image part.
  322. }
  323. // xlsxLegacyDrawing directly maps the legacyDrawing element in the namespace
  324. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  325. // A comment is a rich text note that is attached to, and associated with,
  326. // a cell, separate from other cell content. Comment content is stored
  327. // separate from the cell, and is displayed in a drawing object (like a
  328. // text box) that is separate from, but associated with, a cell. Comments
  329. // are used as reminders, such as noting how a complex formula works, or
  330. // to provide feedback to other users. Comments can also be used to explain
  331. // assumptions made in a formula or to call out something special about the cell.
  332. type xlsxLegacyDrawing struct {
  333. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  334. }