xmlWorkbook.go 15 KB

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