xmlWorksheet.go 15 KB

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