xmlWorksheet.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // Some code of this file reference tealeg/xlsx.
  2. package excelize
  3. import (
  4. "encoding/xml"
  5. )
  6. // xlsxWorksheet directly maps the worksheet element in the namespace
  7. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  8. // currently I have not checked it for completeness - it does as much
  9. // as I need.
  10. type xlsxWorksheet struct {
  11. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
  12. SheetPr xlsxSheetPr `xml:"sheetPr"`
  13. Dimension xlsxDimension `xml:"dimension"`
  14. SheetViews xlsxSheetViews `xml:"sheetViews"`
  15. SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
  16. Cols *xlsxCols `xml:"cols,omitempty"`
  17. SheetData xlsxSheetData `xml:"sheetData"`
  18. MergeCells *xlsxMergeCells `xml:"mergeCells,omitempty"`
  19. PrintOptions xlsxPrintOptions `xml:"printOptions"`
  20. PageMargins xlsxPageMargins `xml:"pageMargins"`
  21. PageSetUp xlsxPageSetUp `xml:"pageSetup"`
  22. HeaderFooter xlsxHeaderFooter `xml:"headerFooter"`
  23. Drawing xlsxDrawing `xml:"drawing"`
  24. }
  25. // xlsxDrawing change r:id to rid in the namespace.
  26. type xlsxDrawing struct {
  27. RID string `xml:"rid,attr"`
  28. }
  29. // xlsxHeaderFooter directly maps the headerFooter element in the namespace
  30. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  31. // currently I have not checked it for completeness - it does as much
  32. // as I need.
  33. type xlsxHeaderFooter struct {
  34. DifferentFirst bool `xml:"differentFirst,attr"`
  35. DifferentOddEven bool `xml:"differentOddEven,attr"`
  36. OddHeader []xlsxOddHeader `xml:"oddHeader"`
  37. OddFooter []xlsxOddFooter `xml:"oddFooter"`
  38. }
  39. // xlsxOddHeader directly maps the oddHeader element in the namespace
  40. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  41. // currently I have not checked it for completeness - it does as much
  42. // as I need.
  43. type xlsxOddHeader struct {
  44. Content string `xml:",chardata"`
  45. }
  46. // xlsxOddFooter directly maps the oddFooter element in the namespace
  47. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  48. // currently I have not checked it for completeness - it does as much
  49. // as I need.
  50. type xlsxOddFooter struct {
  51. Content string `xml:",chardata"`
  52. }
  53. // xlsxPageSetUp directly maps the pageSetup element in the namespace
  54. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  55. // currently I have not checked it for completeness - it does as much
  56. // as I need.
  57. type xlsxPageSetUp struct {
  58. PaperSize string `xml:"paperSize,attr,omitempty"`
  59. Scale int `xml:"scale,attr"`
  60. FirstPageNumber int `xml:"firstPageNumber,attr"`
  61. FitToWidth int `xml:"fitToWidth,attr"`
  62. FitToHeight int `xml:"fitToHeight,attr"`
  63. PageOrder string `xml:"pageOrder,attr,omitempty"`
  64. Orientation string `xml:"orientation,attr,omitempty"`
  65. UsePrinterDefaults bool `xml:"usePrinterDefaults,attr"`
  66. BlackAndWhite bool `xml:"blackAndWhite,attr"`
  67. Draft bool `xml:"draft,attr"`
  68. CellComments string `xml:"cellComments,attr,omitempty"`
  69. UseFirstPageNumber bool `xml:"useFirstPageNumber,attr"`
  70. HorizontalDPI float32 `xml:"horizontalDpi,attr"`
  71. VerticalDPI float32 `xml:"verticalDpi,attr"`
  72. Copies int `xml:"copies,attr"`
  73. }
  74. // xlsxPrintOptions directly maps the printOptions element in the namespace
  75. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  76. // currently I have not checked it for completeness - it does as much
  77. // as I need.
  78. type xlsxPrintOptions struct {
  79. Headings bool `xml:"headings,attr"`
  80. GridLines bool `xml:"gridLines,attr"`
  81. GridLinesSet bool `xml:"gridLinesSet,attr"`
  82. HorizontalCentered bool `xml:"horizontalCentered,attr"`
  83. VerticalCentered bool `xml:"verticalCentered,attr"`
  84. }
  85. // xlsxPageMargins directly maps the pageMargins element in the namespace
  86. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  87. // currently I have not checked it for completeness - it does as much
  88. // as I need.
  89. type xlsxPageMargins struct {
  90. Left float64 `xml:"left,attr"`
  91. Right float64 `xml:"right,attr"`
  92. Top float64 `xml:"top,attr"`
  93. Bottom float64 `xml:"bottom,attr"`
  94. Header float64 `xml:"header,attr"`
  95. Footer float64 `xml:"footer,attr"`
  96. }
  97. // xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
  98. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  99. // currently I have not checked it for completeness - it does as much
  100. // as I need.
  101. type xlsxSheetFormatPr struct {
  102. DefaultColWidth float64 `xml:"defaultColWidth,attr,omitempty"`
  103. DefaultRowHeight float64 `xml:"defaultRowHeight,attr"`
  104. CustomHeight float64 `xml:"customHeight,attr,omitempty"`
  105. ZeroHeight float64 `xml:"zeroHeight,attr,omitempty"`
  106. OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
  107. OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"`
  108. }
  109. // xlsxSheetViews directly maps the sheetViews element in the namespace
  110. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  111. // currently I have not checked it for completeness - it does as much
  112. // as I need.
  113. type xlsxSheetViews struct {
  114. SheetView []xlsxSheetView `xml:"sheetView"`
  115. }
  116. // xlsxSheetView directly maps the sheetView element in the namespace
  117. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  118. // currently I have not checked it for completeness - it does as much
  119. // as I need.
  120. type xlsxSheetView struct {
  121. // WindowProtection bool `xml:"windowProtection,attr"`
  122. // ShowFormulas bool `xml:"showFormulas,attr"`
  123. ShowGridLines string `xml:"showGridLines,attr,omitempty"`
  124. // ShowRowColHeaders bool `xml:"showRowColHeaders,attr"`
  125. // ShowZeros bool `xml:"showZeros,attr"`
  126. // RightToLeft bool `xml:"rightToLeft,attr"`
  127. TabSelected bool `xml:"tabSelected,attr"`
  128. // ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr"`
  129. // DefaultGridColor bool `xml:"defaultGridColor,attr"`
  130. // View string `xml:"view,attr"`
  131. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  132. // ColorId int `xml:"colorId,attr"`
  133. ZoomScale float64 `xml:"zoomScale,attr,omitempty"`
  134. ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr,omitempty"`
  135. ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr,omitempty"`
  136. WorkbookViewID int `xml:"workbookViewId,attr"`
  137. Selection []xlsxSelection `xml:"selection"`
  138. Pane *xlsxPane `xml:"pane,omitempty"`
  139. }
  140. // xlsxSelection directly maps the selection element in the namespace
  141. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  142. // currently I have not checked it for completeness - it does as much
  143. // as I need.
  144. type xlsxSelection struct {
  145. Pane string `xml:"pane,attr,omitempty"`
  146. ActiveCell string `xml:"activeCell,attr,omitempty"`
  147. ActiveCellID int `xml:"activeCellId,attr"`
  148. SQRef string `xml:"sqref,attr"`
  149. }
  150. // xlsxSelection directly maps the selection element in the namespace
  151. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  152. // currently I have not checked it for completeness - it does as much
  153. // as I need.
  154. type xlsxPane struct {
  155. XSplit float64 `xml:"xSplit,attr"`
  156. YSplit float64 `xml:"ySplit,attr"`
  157. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  158. ActivePane string `xml:"activePane,attr,omitempty"`
  159. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  160. }
  161. // xlsxSheetPr directly maps the sheetPr 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 xlsxSheetPr struct {
  166. FilterMode bool `xml:"filterMode,attr"`
  167. PageSetUpPr []xlsxPageSetUpPr `xml:"pageSetUpPr"`
  168. }
  169. // xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
  170. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  171. // currently I have not checked it for completeness - it does as much
  172. // as I need.
  173. type xlsxPageSetUpPr struct {
  174. FitToPage bool `xml:"fitToPage,attr"`
  175. }
  176. // xlsxCols directly maps the cols element in the namespace
  177. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  178. // currently I have not checked it for completeness - it does as much
  179. // as I need.
  180. type xlsxCols struct {
  181. Col []xlsxCol `xml:"col"`
  182. }
  183. // xlsxCol directly maps the col element in the namespace
  184. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  185. // currently I have not checked it for completeness - it does as much
  186. // as I need.
  187. type xlsxCol struct {
  188. Collapsed bool `xml:"collapsed,attr"`
  189. Hidden bool `xml:"hidden,attr"`
  190. Max int `xml:"max,attr"`
  191. Min int `xml:"min,attr"`
  192. Style int `xml:"style,attr"`
  193. Width float64 `xml:"width,attr"`
  194. CustomWidth int `xml:"customWidth,attr,omitempty"`
  195. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  196. }
  197. // xlsxDimension directly maps the dimension element in the namespace
  198. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  199. // currently I have not checked it for completeness - it does as much
  200. // as I need.
  201. type xlsxDimension struct {
  202. Ref string `xml:"ref,attr"`
  203. }
  204. // xlsxSheetData directly maps the sheetData element in the namespace
  205. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  206. // currently I have not checked it for completeness - it does as much
  207. // as I need.
  208. type xlsxSheetData struct {
  209. XMLName xml.Name `xml:"sheetData"`
  210. Row []xlsxRow `xml:"row"`
  211. }
  212. // xlsxRow directly maps the row element in the namespace
  213. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  214. // currently I have not checked it for completeness - it does as much
  215. // as I need.
  216. type xlsxRow struct {
  217. R int `xml:"r,attr"`
  218. Spans string `xml:"spans,attr,omitempty"`
  219. Hidden bool `xml:"hidden,attr,omitempty"`
  220. C []xlsxC `xml:"c"`
  221. Ht string `xml:"ht,attr,omitempty"`
  222. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  223. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  224. }
  225. type xlsxMergeCell struct {
  226. Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both "D3:G4"
  227. }
  228. type xlsxMergeCells struct {
  229. XMLName xml.Name //`xml:"mergeCells,omitempty"`
  230. Count int `xml:"count,attr,omitempty"`
  231. Cells []xlsxMergeCell `xml:"mergeCell,omitempty"`
  232. }
  233. // xlsxC directly maps the c element in the namespace
  234. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  235. // currently I have not checked it for completeness - it does as much
  236. // as I need.
  237. type xlsxC struct {
  238. R string `xml:"r,attr"` // Cell ID, e.g. A1
  239. S int `xml:"s,attr,omitempty"` // Style reference.
  240. // Str string `xml:"str,attr,omitempty"` // Style reference.
  241. T string `xml:"t,attr,omitempty"` // Type.
  242. F *xlsxF `xml:"f,omitempty"` // Formula
  243. V string `xml:"v,omitempty"` // Value
  244. }
  245. // xlsxF directly maps the f element in the namespace
  246. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  247. // currently I have not checked it for completeness - it does as much
  248. // as I need.
  249. type xlsxF struct {
  250. Content string `xml:",chardata"`
  251. T string `xml:"t,attr,omitempty"` // Formula type
  252. Ref string `xml:"ref,attr,omitempty"` // Shared formula ref
  253. Si int `xml:"si,attr,omitempty"` // Shared formula index
  254. }