xmlWorksheet.go 11 KB

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