xmlWorkbook.go 7.1 KB

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