xmlWorkbook.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // Some code of this file reference tealeg/xlsx.
  2. package excelize
  3. import "encoding/xml"
  4. const (
  5. // sheet state values as defined by
  6. // http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
  7. sheetStateVisible = `visible`
  8. sheetStateHidden = `hidden`
  9. sheetStateVeryHidden = `veryHidden`
  10. )
  11. // xmlxWorkbookRels contains xmlxWorkbookRelations
  12. // 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/sheet%d.xml
  18. type xlsxWorkbookRelation struct {
  19. ID string `xml:"Id,attr"`
  20. Target string `xml:",attr"`
  21. Type string `xml:",attr"`
  22. }
  23. // xlsxWorkbook directly maps the workbook element from the namespace
  24. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  25. // currently I have not checked it for completeness - it does as much
  26. // 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. PivotCaches xlsxPivotCaches `xml:"pivotCaches"`
  38. ExtLst xlsxExtLst `xml:"extLst"`
  39. FileRecoveryPr xlsxFileRecoveryPr `xml:"fileRecoveryPr"`
  40. }
  41. // xlsxFileRecoveryPr maps sheet recovery information.
  42. type xlsxFileRecoveryPr struct {
  43. RepairLoad int `xml:"repairLoad,attr,omitempty"`
  44. }
  45. // xlsxWorkbookProtection directly maps the workbookProtection element from the
  46. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  47. // - currently I have not checked it for completeness - it does as
  48. // much as I need.
  49. type xlsxWorkbookProtection struct {
  50. // We don't need this, yet.
  51. }
  52. // xlsxFileVersion directly maps the fileVersion element from the
  53. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  54. // - currently I have not checked it for completeness - it does as
  55. // much as I need.
  56. type xlsxFileVersion struct {
  57. AppName string `xml:"appName,attr,omitempty"`
  58. LastEdited string `xml:"lastEdited,attr,omitempty"`
  59. LowestEdited string `xml:"lowestEdited,attr,omitempty"`
  60. RupBuild string `xml:"rupBuild,attr,omitempty"`
  61. }
  62. // xlsxWorkbookPr directly maps the workbookPr element from the
  63. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  64. // - currently I have not checked it for completeness - it does as
  65. // much as I need.
  66. type xlsxWorkbookPr struct {
  67. DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"`
  68. BackupFile bool `xml:"backupFile,attr,omitempty"`
  69. ShowObjects string `xml:"showObjects,attr,omitempty"`
  70. Date1904 bool `xml:"date1904,attr,omitempty"`
  71. CodeName string `xml:"codeName,attr,omitempty"`
  72. }
  73. // xlsxBookViews directly maps the bookViews element from the
  74. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  75. // - currently I have not checked it for completeness - it does as
  76. // much as I need.
  77. type xlsxBookViews struct {
  78. WorkBookView []xlsxWorkBookView `xml:"workbookView"`
  79. }
  80. // xlsxWorkBookView directly maps the workbookView element from the
  81. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  82. // - currently I have not checked it for completeness - it does as
  83. // much as I need.
  84. type xlsxWorkBookView struct {
  85. ActiveTab int `xml:"activeTab,attr,omitempty"`
  86. FirstSheet int `xml:"firstSheet,attr,omitempty"`
  87. ShowHorizontalScroll bool `xml:"showHorizontalScroll,attr,omitempty"`
  88. ShowVerticalScroll bool `xml:"showVerticalScroll,attr,omitempty"`
  89. ShowSheetTabs bool `xml:"showSheetTabs,attr,omitempty"`
  90. TabRatio int `xml:"tabRatio,attr,omitempty"`
  91. WindowHeight int `xml:"windowHeight,attr,omitempty"`
  92. WindowWidth int `xml:"windowWidth,attr,omitempty"`
  93. XWindow string `xml:"xWindow,attr,omitempty"`
  94. YWindow string `xml:"yWindow,attr,omitempty"`
  95. }
  96. // xlsxSheets directly maps the sheets element from the namespace
  97. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  98. // currently I have not checked it for completeness - it does as much
  99. // as I need.
  100. type xlsxSheets struct {
  101. Sheet []xlsxSheet `xml:"sheet"`
  102. }
  103. // xlsxSheet directly maps the sheet element from the namespace
  104. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  105. // currently I have not checked it for completeness - it does as much
  106. // as I need.
  107. type xlsxSheet struct {
  108. Name string `xml:"name,attr,omitempty"`
  109. SheetID string `xml:"sheetId,attr,omitempty"`
  110. ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  111. State string `xml:"state,attr,omitempty"`
  112. }
  113. // xlsxExternalReferences directly maps the externalReferences element
  114. // of the external workbook references part.
  115. type xlsxExternalReferences struct {
  116. ExternalReference []xlsxExternalReference `xml:"externalReference"`
  117. }
  118. // xlsxExternalReference directly maps the externalReference element
  119. // of the external workbook references part.
  120. type xlsxExternalReference struct {
  121. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  122. }
  123. // xlsxPivotCaches element enumerates pivot cache definition parts
  124. // used by pivot tables and formulas in this workbook.
  125. type xlsxPivotCaches struct {
  126. PivotCache []xlsxPivotCache `xml:"pivotCache"`
  127. }
  128. // xlsxPivotCache directly maps the pivotCache element.
  129. type xlsxPivotCache struct {
  130. CacheID int `xml:"cacheId,attr,omitempty"`
  131. RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  132. }
  133. // extLst element provides a convention for extending spreadsheetML in
  134. // predefined locations. The locations shall be denoted with the extLst
  135. // element, and are called extension lists. Extension list locations
  136. // within the markup document are specified in the markup specification
  137. // and can be used to store extensions to the markup specification,
  138. // whether those are future version extensions of the markup specification
  139. // or are private extensions implemented independently from the markup
  140. // specification. Markup within an extension might not be understood by a
  141. // consumer.
  142. type xlsxExtLst struct {
  143. Ext string `xml:",innerxml"`
  144. }
  145. // xlsxDefinedNames directly maps the definedNames element from the
  146. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  147. // - currently I have not checked it for completeness - it does as
  148. // much as I need.
  149. type xlsxDefinedNames struct {
  150. DefinedName []xlsxDefinedName `xml:"definedName"`
  151. }
  152. // xlsxDefinedName directly maps the definedName element from the
  153. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  154. // - currently I have not checked it for completeness - it does as
  155. // much as I need.
  156. // for a descriptions of the attributes see
  157. // https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.definedname.aspx
  158. type xlsxDefinedName struct {
  159. Data string `xml:",chardata"`
  160. Name string `xml:"name,attr"`
  161. Comment string `xml:"comment,attr,omitempty"`
  162. CustomMenu string `xml:"customMenu,attr,omitempty"`
  163. Description string `xml:"description,attr,omitempty"`
  164. Help string `xml:"help,attr,omitempty"`
  165. ShortcutKey string `xml:"shortcutKey,attr,omitempty"`
  166. StatusBar string `xml:"statusBar,attr,omitempty"`
  167. LocalSheetID int `xml:"localSheetId,attr,omitempty"`
  168. FunctionGroupID int `xml:"functionGroupId,attr,omitempty"`
  169. Function bool `xml:"function,attr,omitempty"`
  170. Hidden bool `xml:"hidden,attr,omitempty"`
  171. VbProcedure bool `xml:"vbProcedure,attr,omitempty"`
  172. PublishToServer bool `xml:"publishToServer,attr,omitempty"`
  173. WorkbookParameter bool `xml:"workbookParameter,attr,omitempty"`
  174. Xlm bool `xml:"xml,attr,omitempty"`
  175. }
  176. // xlsxCalcPr directly maps the calcPr element from the namespace
  177. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  178. // currently I have not checked it for completeness - it does as much
  179. // as I need.
  180. type xlsxCalcPr struct {
  181. CalcID string `xml:"calcId,attr,omitempty"`
  182. IterateCount int `xml:"iterateCount,attr,omitempty"`
  183. RefMode string `xml:"refMode,attr,omitempty"`
  184. Iterate bool `xml:"iterate,attr,omitempty"`
  185. IterateDelta float64 `xml:"iterateDelta,attr,omitempty"`
  186. }