xmlWorkbook.go 12 KB

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