xmlWorksheet.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
  105. OutlineLevelRow uint8 `xml:"outlineLevelRow,attr,omitempty"`
  106. }
  107. // xlsxSheetViews directly maps the sheetViews element in the namespace
  108. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  109. // currently I have not checked it for completeness - it does as much
  110. // as I need.
  111. type xlsxSheetViews struct {
  112. SheetView []xlsxSheetView `xml:"sheetView"`
  113. }
  114. // xlsxSheetView directly maps the sheetView element in the namespace
  115. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  116. // currently I have not checked it for completeness - it does as much
  117. // as I need.
  118. type xlsxSheetView struct {
  119. // WindowProtection bool `xml:"windowProtection,attr"`
  120. // ShowFormulas bool `xml:"showFormulas,attr"`
  121. // ShowGridLines bool `xml:"showGridLines,attr"`
  122. // ShowRowColHeaders bool `xml:"showRowColHeaders,attr"`
  123. // ShowZeros bool `xml:"showZeros,attr"`
  124. // RightToLeft bool `xml:"rightToLeft,attr"`
  125. TabSelected bool `xml:"tabSelected,attr"`
  126. // ShowOutlineSymbols bool `xml:"showOutlineSymbols,attr"`
  127. // DefaultGridColor bool `xml:"defaultGridColor,attr"`
  128. // View string `xml:"view,attr"`
  129. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  130. // ColorId int `xml:"colorId,attr"`
  131. // ZoomScale float64 `xml:"zoomScale,attr"`
  132. // ZoomScaleNormal float64 `xml:"zoomScaleNormal,attr"`
  133. // ZoomScalePageLayoutView float64 `xml:"zoomScalePageLayoutView,attr"`
  134. WorkbookViewID int `xml:"workbookViewId,attr"`
  135. Selection []xlsxSelection `xml:"selection"`
  136. Pane *xlsxPane `xml:"pane,omitempty"`
  137. }
  138. // xlsxSelection directly maps the selection element in the namespace
  139. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  140. // currently I have not checked it for completeness - it does as much
  141. // as I need.
  142. type xlsxSelection struct {
  143. Pane string `xml:"pane,attr,omitempty"`
  144. ActiveCell string `xml:"activeCell,attr"`
  145. ActiveCellID int `xml:"activeCellId,attr"`
  146. SQRef string `xml:"sqref,attr"`
  147. }
  148. // xlsxSelection directly maps the selection element in the namespace
  149. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  150. // currently I have not checked it for completeness - it does as much
  151. // as I need.
  152. type xlsxPane struct {
  153. XSplit float64 `xml:"xSplit,attr"`
  154. YSplit float64 `xml:"ySplit,attr"`
  155. TopLeftCell string `xml:"topLeftCell,attr,omitempty"`
  156. ActivePane string `xml:"activePane,attr,omitempty"`
  157. State string `xml:"state,attr,omitempty"` // Either "split" or "frozen"
  158. }
  159. // xlsxSheetPr directly maps the sheetPr element in the namespace
  160. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  161. // currently I have not checked it for completeness - it does as much
  162. // as I need.
  163. type xlsxSheetPr struct {
  164. FilterMode bool `xml:"filterMode,attr"`
  165. PageSetUpPr []xlsxPageSetUpPr `xml:"pageSetUpPr"`
  166. }
  167. // xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
  168. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  169. // currently I have not checked it for completeness - it does as much
  170. // as I need.
  171. type xlsxPageSetUpPr struct {
  172. FitToPage bool `xml:"fitToPage,attr"`
  173. }
  174. // xlsxCols directly maps the cols element in the namespace
  175. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  176. // currently I have not checked it for completeness - it does as much
  177. // as I need.
  178. type xlsxCols struct {
  179. Col []xlsxCol `xml:"col"`
  180. }
  181. // xlsxCol directly maps the col element in the namespace
  182. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  183. // currently I have not checked it for completeness - it does as much
  184. // as I need.
  185. type xlsxCol struct {
  186. Collapsed bool `xml:"collapsed,attr"`
  187. Hidden bool `xml:"hidden,attr"`
  188. Max int `xml:"max,attr"`
  189. Min int `xml:"min,attr"`
  190. Style int `xml:"style,attr"`
  191. Width float64 `xml:"width,attr"`
  192. CustomWidth int `xml:"customWidth,attr,omitempty"`
  193. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  194. }
  195. // xlsxDimension directly maps the dimension element in the namespace
  196. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  197. // currently I have not checked it for completeness - it does as much
  198. // as I need.
  199. type xlsxDimension struct {
  200. Ref string `xml:"ref,attr"`
  201. }
  202. // xlsxSheetData directly maps the sheetData element in the namespace
  203. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  204. // currently I have not checked it for completeness - it does as much
  205. // as I need.
  206. type xlsxSheetData struct {
  207. XMLName xml.Name `xml:"sheetData"`
  208. Row []xlsxRow `xml:"row"`
  209. }
  210. // xlsxRow directly maps the row element in the namespace
  211. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  212. // currently I have not checked it for completeness - it does as much
  213. // as I need.
  214. type xlsxRow struct {
  215. R int `xml:"r,attr"`
  216. Spans string `xml:"spans,attr,omitempty"`
  217. Hidden bool `xml:"hidden,attr,omitempty"`
  218. C []xlsxC `xml:"c"`
  219. Ht string `xml:"ht,attr,omitempty"`
  220. CustomHeight bool `xml:"customHeight,attr,omitempty"`
  221. OutlineLevel uint8 `xml:"outlineLevel,attr,omitempty"`
  222. }
  223. type xlsxMergeCell struct {
  224. Ref string `xml:"ref,attr"` // ref: horiz "A1:C1", vert "B3:B6", both "D3:G4"
  225. }
  226. type xlsxMergeCells struct {
  227. XMLName xml.Name //`xml:"mergeCells,omitempty"`
  228. Count int `xml:"count,attr,omitempty"`
  229. Cells []xlsxMergeCell `xml:"mergeCell,omitempty"`
  230. }
  231. // xlsxC directly maps the c element in the namespace
  232. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  233. // currently I have not checked it for completeness - it does as much
  234. // as I need.
  235. type xlsxC struct {
  236. R string `xml:"r,attr"` // Cell ID, e.g. A1
  237. S int `xml:"s,attr,omitempty"` // Style reference.
  238. // Str string `xml:"str,attr,omitempty"` // Style reference.
  239. T string `xml:"t,attr,omitempty"` // Type.
  240. F *xlsxF `xml:"f,omitempty"` // Formula
  241. V string `xml:"v,omitempty"` // Value
  242. }
  243. // xlsxF directly maps the f element in the namespace
  244. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  245. // currently I have not checked it for completeness - it does as much
  246. // as I need.
  247. type xlsxF struct {
  248. Content string `xml:",chardata"`
  249. T string `xml:"t,attr,omitempty"` // Formula type
  250. Ref string `xml:"ref,attr,omitempty"` // Shared formula ref
  251. Si int `xml:"si,attr,omitempty"` // Shared formula index
  252. }