xmlWorkbook.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package excelize
  2. import "encoding/xml"
  3. const (
  4. // sheet state values as defined by
  5. // http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
  6. sheetStateVisible = `visible`
  7. sheetStateHidden = `hidden`
  8. sheetStateVeryHidden = `veryHidden`
  9. )
  10. // xmlxWorkbookRels contains xmlxWorkbookRelations
  11. // which maps sheet id and sheet XML.
  12. type xlsxWorkbookRels struct {
  13. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/relationships Relationships"`
  14. Relationships []xlsxWorkbookRelation `xml:"Relationship"`
  15. }
  16. // xmlxWorkbookRelation maps sheet id and xl/worksheets/sheet%d.xml
  17. type xlsxWorkbookRelation struct {
  18. ID string `xml:"Id,attr"`
  19. Target string `xml:",attr"`
  20. Type string `xml:",attr"`
  21. }
  22. // xlsxWorkbook directly maps the workbook element from the namespace
  23. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  24. // currently I have not checked it for completeness - it does as much
  25. // as I need.
  26. type xlsxWorkbook struct {
  27. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main workbook"`
  28. FileVersion *xlsxFileVersion `xml:"fileVersion"`
  29. WorkbookPr *xlsxWorkbookPr `xml:"workbookPr"`
  30. WorkbookProtection *xlsxWorkbookProtection `xml:"workbookProtection"`
  31. BookViews xlsxBookViews `xml:"bookViews"`
  32. Sheets xlsxSheets `xml:"sheets"`
  33. ExternalReferences *xlsxExternalReferences `xml:"externalReferences"`
  34. DefinedNames *xlsxDefinedNames `xml:"definedNames"`
  35. CalcPr *xlsxCalcPr `xml:"calcPr"`
  36. PivotCaches *xlsxPivotCaches `xml:"pivotCaches"`
  37. ExtLst *xlsxExtLst `xml:"extLst"`
  38. FileRecoveryPr *xlsxFileRecoveryPr `xml:"fileRecoveryPr"`
  39. }
  40. // xlsxFileRecoveryPr maps sheet recovery information. This element
  41. // defines properties that track the state of the workbook file, such
  42. // as whether the file was saved during a crash, or whether it should
  43. // be opened in auto-recover mode.
  44. type xlsxFileRecoveryPr struct {
  45. AutoRecover bool `xml:"autoRecover,attr,omitempty"`
  46. CrashSave bool `xml:"crashSave,attr,omitempty"`
  47. DataExtractLoad bool `xml:"dataExtractLoad,attr,omitempty"`
  48. RepairLoad bool `xml:"repairLoad,attr,omitempty"`
  49. }
  50. // xlsxWorkbookProtection directly maps the workbookProtection element.
  51. // This element specifies options for protecting data in the workbook.
  52. // Applications might use workbook protection to prevent anyone from
  53. // accidentally changing, moving, or deleting important data. This
  54. // protection can be ignored by applications which choose not to support
  55. // this optional protection mechanism.
  56. // When a password is to be hashed and stored in this element, it shall
  57. // be hashed as defined below, starting from a UTF-16LE encoded string
  58. // value. If there is a leading BOM character (U+FEFF) in the encoded
  59. // password it is removed before hash calculation.
  60. type xlsxWorkbookProtection struct {
  61. LockRevision bool `xml:"lockRevision,attr,omitempty"`
  62. LockStructure bool `xml:"lockStructure,attr,omitempty"`
  63. LockWindows bool `xml:"lockWindows,attr,omitempty"`
  64. RevisionsAlgorithmName string `xml:"revisionsAlgorithmName,attr,omitempty"`
  65. RevisionsHashValue string `xml:"revisionsHashValue,attr,omitempty"`
  66. RevisionsSaltValue string `xml:"revisionsSaltValue,attr,omitempty"`
  67. RevisionsSpinCount int `xml:"revisionsSpinCount,attr,omitempty"`
  68. WorkbookAlgorithmName string `xml:"workbookAlgorithmName,attr,omitempty"`
  69. WorkbookHashValue string `xml:"workbookHashValue,attr,omitempty"`
  70. WorkbookSaltValue string `xml:"workbookSaltValue,attr,omitempty"`
  71. WorkbookSpinCount int `xml:"workbookSpinCount,attr,omitempty"`
  72. }
  73. // xlsxFileVersion directly maps the fileVersion element. This element
  74. // defines properties that track which version of the application accessed
  75. // the data and source code contained in the file.
  76. type xlsxFileVersion struct {
  77. AppName string `xml:"appName,attr,omitempty"`
  78. CodeName string `xml:"codeName,attr,omitempty"`
  79. LastEdited string `xml:"lastEdited,attr,omitempty"`
  80. LowestEdited string `xml:"lowestEdited,attr,omitempty"`
  81. RupBuild string `xml:"rupBuild,attr,omitempty"`
  82. }
  83. // xlsxWorkbookPr directly maps the workbookPr element from the
  84. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  85. // This element defines a collection of workbook properties.
  86. type xlsxWorkbookPr struct {
  87. AllowRefreshQuery bool `xml:"allowRefreshQuery,attr,omitempty"`
  88. AutoCompressPictures bool `xml:"autoCompressPictures,attr,omitempty"`
  89. BackupFile bool `xml:"backupFile,attr,omitempty"`
  90. CheckCompatibility bool `xml:"checkCompatibility,attr,omitempty"`
  91. CodeName string `xml:"codeName,attr,omitempty"`
  92. Date1904 bool `xml:"date1904,attr,omitempty"`
  93. DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"`
  94. FilterPrivacy bool `xml:"filterPrivacy,attr,omitempty"`
  95. HidePivotFieldList bool `xml:"hidePivotFieldList,attr,omitempty"`
  96. PromptedSolutions bool `xml:"promptedSolutions,attr,omitempty"`
  97. PublishItems bool `xml:"publishItems,attr,omitempty"`
  98. RefreshAllConnections bool `xml:"refreshAllConnections,attr,omitempty"`
  99. SaveExternalLinkValues bool `xml:"saveExternalLinkValues,attr,omitempty"`
  100. ShowBorderUnselectedTables bool `xml:"showBorderUnselectedTables,attr,omitempty"`
  101. ShowInkAnnotation bool `xml:"showInkAnnotation,attr,omitempty"`
  102. ShowObjects string `xml:"showObjects,attr,omitempty"`
  103. ShowPivotChartFilter bool `xml:"showPivotChartFilter,attr,omitempty"`
  104. UpdateLinks string `xml:"updateLinks,attr,omitempty"`
  105. }
  106. // xlsxBookViews directly maps the bookViews element. This element specifies
  107. // the collection of workbook views of the enclosing workbook. Each view can
  108. // specify a window position, filter options, and other configurations. There
  109. // is no limit on the number of workbook views that can be defined for a workbook.
  110. type xlsxBookViews struct {
  111. WorkBookView []xlsxWorkBookView `xml:"workbookView"`
  112. }
  113. // xlsxWorkBookView directly maps the workbookView element from the
  114. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  115. // This element specifies a single Workbook view.
  116. type xlsxWorkBookView struct {
  117. ActiveTab int `xml:"activeTab,attr,omitempty"`
  118. AutoFilterDateGrouping bool `xml:"autoFilterDateGrouping,attr,omitempty"`
  119. FirstSheet int `xml:"firstSheet,attr,omitempty"`
  120. Minimized bool `xml:"minimized,attr,omitempty"`
  121. ShowHorizontalScroll bool `xml:"showHorizontalScroll,attr,omitempty"`
  122. ShowSheetTabs bool `xml:"showSheetTabs,attr,omitempty"`
  123. ShowVerticalScroll bool `xml:"showVerticalScroll,attr,omitempty"`
  124. TabRatio int `xml:"tabRatio,attr,omitempty"`
  125. Visibility string `xml:"visibility,attr,omitempty"`
  126. WindowHeight int `xml:"windowHeight,attr,omitempty"`
  127. WindowWidth int `xml:"windowWidth,attr,omitempty"`
  128. XWindow string `xml:"xWindow,attr,omitempty"`
  129. YWindow string `xml:"yWindow,attr,omitempty"`
  130. }
  131. // xlsxSheets directly maps the sheets element from the namespace
  132. // http://schemas.openxmlformats.org/spreadsheetml/2006/main.
  133. type xlsxSheets struct {
  134. Sheet []xlsxSheet `xml:"sheet"`
  135. }
  136. // xlsxSheet directly maps the sheet element from the namespace
  137. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  138. // currently I have not checked it for completeness - it does as much
  139. // as I need.
  140. type xlsxSheet struct {
  141. Name string `xml:"name,attr,omitempty"`
  142. SheetID string `xml:"sheetId,attr,omitempty"`
  143. ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  144. State string `xml:"state,attr,omitempty"`
  145. }
  146. // xlsxExternalReferences directly maps the externalReferences element
  147. // of the external workbook references part.
  148. type xlsxExternalReferences struct {
  149. ExternalReference []xlsxExternalReference `xml:"externalReference"`
  150. }
  151. // xlsxExternalReference directly maps the externalReference element
  152. // of the external workbook references part.
  153. type xlsxExternalReference struct {
  154. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  155. }
  156. // xlsxPivotCaches element enumerates pivot cache definition parts
  157. // used by pivot tables and formulas in this workbook.
  158. type xlsxPivotCaches struct {
  159. PivotCache []xlsxPivotCache `xml:"pivotCache"`
  160. }
  161. // xlsxPivotCache directly maps the pivotCache element.
  162. type xlsxPivotCache struct {
  163. CacheID int `xml:"cacheId,attr,omitempty"`
  164. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  165. }
  166. // extLst element provides a convention for extending spreadsheetML in
  167. // predefined locations. The locations shall be denoted with the extLst
  168. // element, and are called extension lists. Extension list locations
  169. // within the markup document are specified in the markup specification
  170. // and can be used to store extensions to the markup specification,
  171. // whether those are future version extensions of the markup specification
  172. // or are private extensions implemented independently from the markup
  173. // specification. Markup within an extension might not be understood by a
  174. // consumer.
  175. type xlsxExtLst struct {
  176. Ext string `xml:",innerxml"`
  177. }
  178. // xlsxDefinedNames directly maps the definedNames element. This element
  179. // defines the collection of defined names for this workbook. Defined
  180. // names are descriptive names to represent cells, ranges of cells,
  181. // formulas, or constant values. Defined names can be used to represent
  182. // a range on any worksheet.
  183. type xlsxDefinedNames struct {
  184. DefinedName []xlsxDefinedName `xml:"definedName"`
  185. }
  186. // xlsxDefinedName directly maps the definedName element from the
  187. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  188. // This element defines a defined name within this workbook. A defined
  189. // name is descriptive text that is used to represents a cell, range of
  190. // cells, formula, or constant value. For a descriptions of the attributes
  191. // see https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.definedname.aspx
  192. type xlsxDefinedName struct {
  193. Comment string `xml:"comment,attr,omitempty"`
  194. CustomMenu string `xml:"customMenu,attr,omitempty"`
  195. Description string `xml:"description,attr,omitempty"`
  196. Function bool `xml:"function,attr,omitempty"`
  197. FunctionGroupID int `xml:"functionGroupId,attr,omitempty"`
  198. Help string `xml:"help,attr,omitempty"`
  199. Hidden bool `xml:"hidden,attr,omitempty"`
  200. LocalSheetID int `xml:"localSheetId,attr,omitempty"`
  201. Name string `xml:"name,attr,omitempty"`
  202. PublishToServer bool `xml:"publishToServer,attr,omitempty"`
  203. ShortcutKey string `xml:"shortcutKey,attr,omitempty"`
  204. StatusBar string `xml:"statusBar,attr,omitempty"`
  205. VbProcedure bool `xml:"vbProcedure,attr,omitempty"`
  206. WorkbookParameter bool `xml:"workbookParameter,attr,omitempty"`
  207. Xlm bool `xml:"xml,attr,omitempty"`
  208. Data string `xml:",chardata"`
  209. }
  210. // xlsxCalcPr directly maps the calcPr element. This element defines the
  211. // collection of properties the application uses to record calculation
  212. // status and details. Calculation is the process of computing formulas
  213. // and then displaying the results as values in the cells that contain
  214. // the formulas.
  215. type xlsxCalcPr struct {
  216. CalcCompleted bool `xml:"calcCompleted,attr,omitempty"`
  217. CalcID string `xml:"calcId,attr,omitempty"`
  218. CalcMode string `xml:"calcMode,attr,omitempty"`
  219. CalcOnSave bool `xml:"calcOnSave,attr,omitempty"`
  220. ConcurrentCalc bool `xml:"concurrentCalc,attr,omitempty"`
  221. ConcurrentManualCount int `xml:"concurrentManualCount,attr,omitempty"`
  222. ForceFullCalc bool `xml:"forceFullCalc,attr,omitempty"`
  223. FullCalcOnLoad bool `xml:"fullCalcOnLoad,attr,omitempty"`
  224. FullPrecision bool `xml:"fullPrecision,attr,omitempty"`
  225. Iterate bool `xml:"iterate,attr,omitempty"`
  226. IterateCount int `xml:"iterateCount,attr,omitempty"`
  227. IterateDelta float64 `xml:"iterateDelta,attr,omitempty"`
  228. RefMode string `xml:"refMode,attr,omitempty"`
  229. }