xmlWorkbook.go 15 KB

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