xmlWorkbook.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package excelize
  2. import (
  3. "encoding/xml"
  4. )
  5. const (
  6. // sheet state values as defined by
  7. // http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
  8. sheetStateVisible = "visible"
  9. sheetStateHidden = "hidden"
  10. sheetStateVeryHidden = "veryHidden"
  11. )
  12. // xmlxWorkbookRels contains xmlxWorkbookRelations
  13. // which maps sheet id and sheet XML
  14. type xlsxWorkbookRels struct {
  15. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/relationships Relationships"`
  16. Relationships []xlsxWorkbookRelation `xml:"Relationship"`
  17. }
  18. // xmlxWorkbookRelation maps sheet id and xl/worksheets/sheet%d.xml
  19. type xlsxWorkbookRelation struct {
  20. Id string `xml:",attr"`
  21. Target string `xml:",attr"`
  22. Type string `xml:",attr"`
  23. }
  24. // xlsxWorkbook directly maps the workbook element from the namespace
  25. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  26. // currently I have not checked it for completeness - it does as much
  27. // as I need.
  28. type xlsxWorkbook struct {
  29. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main workbook"`
  30. FileVersion xlsxFileVersion `xml:"fileVersion"`
  31. WorkbookPr xlsxWorkbookPr `xml:"workbookPr"`
  32. WorkbookProtection xlsxWorkbookProtection `xml:"workbookProtection"`
  33. BookViews xlsxBookViews `xml:"bookViews"`
  34. Sheets xlsxSheets `xml:"sheets"`
  35. DefinedNames xlsxDefinedNames `xml:"definedNames"`
  36. CalcPr xlsxCalcPr `xml:"calcPr"`
  37. FileRecoveryPr xlsxFileRecoveryPr `xml:"fileRecoveryPr"`
  38. }
  39. // xlsxFileRecoveryPr maps sheet recovery information
  40. type xlsxFileRecoveryPr struct {
  41. RepairLoad int `xml:"repairLoad,attr"`
  42. }
  43. // xlsxWorkbookProtection directly maps the workbookProtection element from the
  44. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  45. // - currently I have not checked it for completeness - it does as
  46. // much as I need.
  47. type xlsxWorkbookProtection struct {
  48. // We don't need this, yet.
  49. }
  50. // xlsxFileVersion directly maps the fileVersion element from the
  51. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  52. // - currently I have not checked it for completeness - it does as
  53. // much as I need.
  54. type xlsxFileVersion struct {
  55. AppName string `xml:"appName,attr,omitempty"`
  56. LastEdited string `xml:"lastEdited,attr,omitempty"`
  57. LowestEdited string `xml:"lowestEdited,attr,omitempty"`
  58. RupBuild string `xml:"rupBuild,attr,omitempty"`
  59. }
  60. // xlsxWorkbookPr directly maps the workbookPr element from the
  61. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  62. // - currently I have not checked it for completeness - it does as
  63. // much as I need.
  64. type xlsxWorkbookPr struct {
  65. DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"`
  66. BackupFile bool `xml:"backupFile,attr,omitempty"`
  67. ShowObjects string `xml:"showObjects,attr,omitempty"`
  68. Date1904 bool `xml:"date1904,attr"`
  69. }
  70. // xlsxBookViews directly maps the bookViews element from the
  71. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  72. // - currently I have not checked it for completeness - it does as
  73. // much as I need.
  74. type xlsxBookViews struct {
  75. WorkBookView []xlsxWorkBookView `xml:"workbookView"`
  76. }
  77. // xlsxWorkBookView directly maps the workbookView element from the
  78. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  79. // - currently I have not checked it for completeness - it does as
  80. // much as I need.
  81. type xlsxWorkBookView struct {
  82. ActiveTab int `xml:"activeTab,attr,omitempty"`
  83. FirstSheet int `xml:"firstSheet,attr,omitempty"`
  84. ShowHorizontalScroll bool `xml:"showHorizontalScroll,attr,omitempty"`
  85. ShowVerticalScroll bool `xml:"showVerticalScroll,attr,omitempty"`
  86. ShowSheetTabs bool `xml:"showSheetTabs,attr,omitempty"`
  87. TabRatio int `xml:"tabRatio,attr,omitempty"`
  88. WindowHeight int `xml:"windowHeight,attr,omitempty"`
  89. WindowWidth int `xml:"windowWidth,attr,omitempty"`
  90. XWindow string `xml:"xWindow,attr,omitempty"`
  91. YWindow string `xml:"yWindow,attr,omitempty"`
  92. }
  93. // xlsxSheets directly maps the sheets element from the namespace
  94. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  95. // currently I have not checked it for completeness - it does as much
  96. // as I need.
  97. type xlsxSheets struct {
  98. Sheet []xlsxSheet `xml:"sheet"`
  99. }
  100. // xlsxSheet directly maps the sheet element from the namespace
  101. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  102. // currently I have not checked it for completeness - it does as much
  103. // as I need.
  104. type xlsxSheet struct {
  105. Name string `xml:"name,attr,omitempty"`
  106. SheetId string `xml:"sheetId,attr,omitempty"`
  107. Id string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
  108. State string `xml:"state,attr,omitempty"`
  109. }
  110. // xlsxDefinedNames directly maps the definedNames element from the
  111. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  112. // - currently I have not checked it for completeness - it does as
  113. // much as I need.
  114. type xlsxDefinedNames struct {
  115. DefinedName []xlsxDefinedName `xml:"definedName"`
  116. }
  117. // xlsxDefinedName directly maps the definedName element from the
  118. // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
  119. // - currently I have not checked it for completeness - it does as
  120. // much as I need.
  121. // for a descriptions of the attributes see
  122. // https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.definedname.aspx
  123. type xlsxDefinedName struct {
  124. Data string `xml:",chardata"`
  125. Name string `xml:"name,attr"`
  126. Comment string `xml:"comment,attr,omitempty"`
  127. CustomMenu string `xml:"customMenu,attr,omitempty"`
  128. Description string `xml:"description,attr,omitempty"`
  129. Help string `xml:"help,attr,omitempty"`
  130. ShortcutKey string `xml:"shortcutKey,attr,omitempty"`
  131. StatusBar string `xml:"statusBar,attr,omitempty"`
  132. LocalSheetID int `xml:"localSheetId,attr,omitempty"`
  133. FunctionGroupID int `xml:"functionGroupId,attr,omitempty"`
  134. Function bool `xml:"function,attr,omitempty"`
  135. Hidden bool `xml:"hidden,attr,omitempty"`
  136. VbProcedure bool `xml:"vbProcedure,attr,omitempty"`
  137. PublishToServer bool `xml:"publishToServer,attr,omitempty"`
  138. WorkbookParameter bool `xml:"workbookParameter,attr,omitempty"`
  139. Xlm bool `xml:"xml,attr,omitempty"`
  140. }
  141. // xlsxCalcPr directly maps the calcPr element from the namespace
  142. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  143. // currently I have not checked it for completeness - it does as much
  144. // as I need.
  145. type xlsxCalcPr struct {
  146. CalcId string `xml:"calcId,attr,omitempty"`
  147. IterateCount int `xml:"iterateCount,attr,omitempty"`
  148. RefMode string `xml:"refMode,attr,omitempty"`
  149. Iterate bool `xml:"iterate,attr,omitempty"`
  150. IterateDelta float64 `xml:"iterateDelta,attr,omitempty"`
  151. }