xmlWorkbook.go 12 KB

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