xmlWorkbook.go 12 KB

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