sheet_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. package xlsx
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. . "gopkg.in/check.v1"
  6. )
  7. type SheetSuite struct{}
  8. var _ = Suite(&SheetSuite{})
  9. // Test we can add a Row to a Sheet
  10. func (s *SheetSuite) TestAddRow(c *C) {
  11. var f *File
  12. f = NewFile()
  13. sheet, _ := f.AddSheet("MySheet")
  14. row := sheet.AddRow()
  15. c.Assert(row, NotNil)
  16. c.Assert(len(sheet.Rows), Equals, 1)
  17. }
  18. // Test we can get row by index from Sheet
  19. func (s *SheetSuite) TestGetRowByIndex(c *C) {
  20. var f *File
  21. f = NewFile()
  22. sheet, _ := f.AddSheet("MySheet")
  23. row := sheet.Row(10)
  24. c.Assert(row, NotNil)
  25. c.Assert(len(sheet.Rows), Equals, 11)
  26. row = sheet.Row(2)
  27. c.Assert(row, NotNil)
  28. c.Assert(len(sheet.Rows), Equals, 11)
  29. }
  30. func (s *SheetSuite) TestMakeXLSXSheetFromRows(c *C) {
  31. file := NewFile()
  32. sheet, _ := file.AddSheet("Sheet1")
  33. row := sheet.AddRow()
  34. cell := row.AddCell()
  35. cell.Value = "A cell!"
  36. refTable := NewSharedStringRefTable()
  37. styles := newXlsxStyleSheet(nil)
  38. xSheet := sheet.makeXLSXSheet(refTable, styles)
  39. c.Assert(xSheet.Dimension.Ref, Equals, "A1")
  40. c.Assert(xSheet.SheetData.Row, HasLen, 1)
  41. xRow := xSheet.SheetData.Row[0]
  42. c.Assert(xRow.R, Equals, 1)
  43. c.Assert(xRow.Spans, Equals, "")
  44. c.Assert(xRow.C, HasLen, 1)
  45. xC := xRow.C[0]
  46. c.Assert(xC.R, Equals, "A1")
  47. c.Assert(xC.S, Equals, 0)
  48. c.Assert(xC.T, Equals, "s") // Shared string type
  49. c.Assert(xC.V, Equals, "0") // reference to shared string
  50. xSST := refTable.makeXLSXSST()
  51. c.Assert(xSST.Count, Equals, 1)
  52. c.Assert(xSST.UniqueCount, Equals, 1)
  53. c.Assert(xSST.SI, HasLen, 1)
  54. xSI := xSST.SI[0]
  55. c.Assert(xSI.T, Equals, "A cell!")
  56. }
  57. // Test if the NumFmts assigned properly according the FormatCode in cell.
  58. func (s *SheetSuite) TestMakeXLSXSheetWithNumFormats(c *C) {
  59. file := NewFile()
  60. sheet, _ := file.AddSheet("Sheet1")
  61. row := sheet.AddRow()
  62. cell1 := row.AddCell()
  63. cell1.Value = "A cell!"
  64. cell1.NumFmt = "general"
  65. cell2 := row.AddCell()
  66. cell2.Value = "37947.7500001"
  67. cell2.NumFmt = "0"
  68. cell3 := row.AddCell()
  69. cell3.Value = "37947.7500001"
  70. cell3.NumFmt = "mm-dd-yy"
  71. cell4 := row.AddCell()
  72. cell4.Value = "37947.7500001"
  73. cell4.NumFmt = "hh:mm:ss"
  74. refTable := NewSharedStringRefTable()
  75. styles := newXlsxStyleSheet(nil)
  76. worksheet := sheet.makeXLSXSheet(refTable, styles)
  77. c.Assert(styles.CellStyleXfs, IsNil)
  78. c.Assert(styles.CellXfs.Count, Equals, 4)
  79. c.Assert(styles.CellXfs.Xf[0].NumFmtId, Equals, 0)
  80. c.Assert(styles.CellXfs.Xf[1].NumFmtId, Equals, 1)
  81. c.Assert(styles.CellXfs.Xf[2].NumFmtId, Equals, 14)
  82. c.Assert(styles.CellXfs.Xf[3].NumFmtId, Equals, 164)
  83. c.Assert(styles.NumFmts.Count, Equals, 1)
  84. c.Assert(styles.NumFmts.NumFmt[0].NumFmtId, Equals, 164)
  85. c.Assert(styles.NumFmts.NumFmt[0].FormatCode, Equals, "hh:mm:ss")
  86. // Finally we check that the cell points to the right CellXf /
  87. // CellStyleXf.
  88. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 0)
  89. c.Assert(worksheet.SheetData.Row[0].C[1].S, Equals, 1)
  90. }
  91. // When we create the xlsxSheet we also populate the xlsxStyles struct
  92. // with style information.
  93. func (s *SheetSuite) TestMakeXLSXSheetAlsoPopulatesXLSXSTyles(c *C) {
  94. file := NewFile()
  95. sheet, _ := file.AddSheet("Sheet1")
  96. row := sheet.AddRow()
  97. cell1 := row.AddCell()
  98. cell1.Value = "A cell!"
  99. style1 := NewStyle()
  100. style1.Font = *NewFont(10, "Verdana")
  101. style1.Fill = *NewFill("solid", "FFFFFFFF", "00000000")
  102. style1.Border = *NewBorder("none", "thin", "none", "thin")
  103. cell1.SetStyle(style1)
  104. // We need a second style to check that Xfs are populated correctly.
  105. cell2 := row.AddCell()
  106. cell2.Value = "Another cell!"
  107. style2 := NewStyle()
  108. style2.Font = *NewFont(10, "Verdana")
  109. style2.Fill = *NewFill("solid", "FFFFFFFF", "00000000")
  110. style2.Border = *NewBorder("none", "thin", "none", "thin")
  111. cell2.SetStyle(style2)
  112. refTable := NewSharedStringRefTable()
  113. styles := newXlsxStyleSheet(nil)
  114. worksheet := sheet.makeXLSXSheet(refTable, styles)
  115. c.Assert(styles.Fonts.Count, Equals, 2)
  116. c.Assert(styles.Fonts.Font[0].Sz.Val, Equals, "12")
  117. c.Assert(styles.Fonts.Font[0].Name.Val, Equals, "Verdana")
  118. c.Assert(styles.Fonts.Font[1].Sz.Val, Equals, "10")
  119. c.Assert(styles.Fonts.Font[1].Name.Val, Equals, "Verdana")
  120. c.Assert(styles.Fills.Count, Equals, 3)
  121. c.Assert(styles.Fills.Fill[0].PatternFill.PatternType, Equals, "none")
  122. c.Assert(styles.Fills.Fill[0].PatternFill.FgColor.RGB, Equals, "FFFFFFFF")
  123. c.Assert(styles.Fills.Fill[0].PatternFill.BgColor.RGB, Equals, "00000000")
  124. c.Assert(styles.Borders.Count, Equals, 2)
  125. c.Assert(styles.Borders.Border[1].Left.Style, Equals, "none")
  126. c.Assert(styles.Borders.Border[1].Right.Style, Equals, "thin")
  127. c.Assert(styles.Borders.Border[1].Top.Style, Equals, "none")
  128. c.Assert(styles.Borders.Border[1].Bottom.Style, Equals, "thin")
  129. c.Assert(styles.CellStyleXfs, IsNil)
  130. c.Assert(styles.CellXfs.Count, Equals, 2)
  131. c.Assert(styles.CellXfs.Xf[0].FontId, Equals, 0)
  132. c.Assert(styles.CellXfs.Xf[0].FillId, Equals, 0)
  133. c.Assert(styles.CellXfs.Xf[0].BorderId, Equals, 0)
  134. // Finally we check that the cell points to the right CellXf /
  135. // CellStyleXf.
  136. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 1)
  137. c.Assert(worksheet.SheetData.Row[0].C[1].S, Equals, 1)
  138. }
  139. // If the column width is not customised, the xslxCol.CustomWidth field is set to 0.
  140. func (s *SheetSuite) TestMakeXLSXSheetDefaultsCustomColWidth(c *C) {
  141. file := NewFile()
  142. sheet, _ := file.AddSheet("Sheet1")
  143. row := sheet.AddRow()
  144. cell1 := row.AddCell()
  145. cell1.Value = "A cell!"
  146. refTable := NewSharedStringRefTable()
  147. styles := newXlsxStyleSheet(nil)
  148. worksheet := sheet.makeXLSXSheet(refTable, styles)
  149. c.Assert(worksheet.Cols.Col[0].CustomWidth, Equals, false)
  150. }
  151. // If the column width is customised, the xslxCol.CustomWidth field is set to 1.
  152. func (s *SheetSuite) TestMakeXLSXSheetSetsCustomColWidth(c *C) {
  153. file := NewFile()
  154. sheet, _ := file.AddSheet("Sheet1")
  155. row := sheet.AddRow()
  156. cell1 := row.AddCell()
  157. cell1.Value = "A cell!"
  158. err := sheet.SetColWidth(0, 1, 10.5)
  159. c.Assert(err, IsNil)
  160. refTable := NewSharedStringRefTable()
  161. styles := newXlsxStyleSheet(nil)
  162. worksheet := sheet.makeXLSXSheet(refTable, styles)
  163. c.Assert(worksheet.Cols.Col[1].CustomWidth, Equals, true)
  164. }
  165. func (s *SheetSuite) TestMarshalSheet(c *C) {
  166. file := NewFile()
  167. sheet, _ := file.AddSheet("Sheet1")
  168. row := sheet.AddRow()
  169. cell := row.AddCell()
  170. cell.Value = "A cell!"
  171. refTable := NewSharedStringRefTable()
  172. styles := newXlsxStyleSheet(nil)
  173. xSheet := sheet.makeXLSXSheet(refTable, styles)
  174. output := bytes.NewBufferString(xml.Header)
  175. body, err := xml.Marshal(xSheet)
  176. c.Assert(err, IsNil)
  177. c.Assert(body, NotNil)
  178. _, err = output.Write(body)
  179. c.Assert(err, IsNil)
  180. expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
  181. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr filterMode="false"><pageSetUpPr fitToPage="false"></pageSetUpPr></sheetPr><dimension ref="A1"></dimension><sheetViews><sheetView windowProtection="false" showFormulas="false" showGridLines="true" showRowColHeaders="true" showZeros="true" rightToLeft="false" tabSelected="true" showOutlineSymbols="true" defaultGridColor="true" view="normal" topLeftCell="A1" colorId="64" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100" workbookViewId="0"><selection pane="topLeft" activeCell="A1" activeCellId="0" sqref="A1"></selection></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.85"></sheetFormatPr><cols><col collapsed="false" hidden="false" max="1" min="1" style="0" width="9.5"></col></cols><sheetData><row r="1"><c r="A1" t="s"><v>0</v></c></row></sheetData><printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"></printOptions><pageMargins left="0.7875" right="0.7875" top="1.05277777777778" bottom="1.05277777777778" header="0.7875" footer="0.7875"></pageMargins><pageSetup paperSize="9" scale="100" firstPageNumber="1" fitToWidth="1" fitToHeight="1" pageOrder="downThenOver" orientation="portrait" usePrinterDefaults="false" blackAndWhite="false" draft="false" cellComments="none" useFirstPageNumber="true" horizontalDpi="300" verticalDpi="300" copies="1"></pageSetup><headerFooter differentFirst="false" differentOddEven="false"><oddHeader>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12&amp;A</oddHeader><oddFooter>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12Page &amp;P</oddFooter></headerFooter></worksheet>`
  182. c.Assert(output.String(), Equals, expectedXLSXSheet)
  183. }
  184. func (s *SheetSuite) TestMarshalSheetWithMultipleCells(c *C) {
  185. file := NewFile()
  186. sheet, _ := file.AddSheet("Sheet1")
  187. row := sheet.AddRow()
  188. cell := row.AddCell()
  189. cell.Value = "A cell (with value 1)!"
  190. cell = row.AddCell()
  191. cell.Value = "A cell (with value 2)!"
  192. refTable := NewSharedStringRefTable()
  193. styles := newXlsxStyleSheet(nil)
  194. xSheet := sheet.makeXLSXSheet(refTable, styles)
  195. output := bytes.NewBufferString(xml.Header)
  196. body, err := xml.Marshal(xSheet)
  197. c.Assert(err, IsNil)
  198. c.Assert(body, NotNil)
  199. _, err = output.Write(body)
  200. c.Assert(err, IsNil)
  201. expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
  202. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr filterMode="false"><pageSetUpPr fitToPage="false"></pageSetUpPr></sheetPr><dimension ref="A1:B1"></dimension><sheetViews><sheetView windowProtection="false" showFormulas="false" showGridLines="true" showRowColHeaders="true" showZeros="true" rightToLeft="false" tabSelected="true" showOutlineSymbols="true" defaultGridColor="true" view="normal" topLeftCell="A1" colorId="64" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100" workbookViewId="0"><selection pane="topLeft" activeCell="A1" activeCellId="0" sqref="A1"></selection></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.85"></sheetFormatPr><cols><col collapsed="false" hidden="false" max="1" min="1" style="0" width="9.5"></col><col collapsed="false" hidden="false" max="2" min="2" style="0" width="9.5"></col></cols><sheetData><row r="1"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row></sheetData><printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"></printOptions><pageMargins left="0.7875" right="0.7875" top="1.05277777777778" bottom="1.05277777777778" header="0.7875" footer="0.7875"></pageMargins><pageSetup paperSize="9" scale="100" firstPageNumber="1" fitToWidth="1" fitToHeight="1" pageOrder="downThenOver" orientation="portrait" usePrinterDefaults="false" blackAndWhite="false" draft="false" cellComments="none" useFirstPageNumber="true" horizontalDpi="300" verticalDpi="300" copies="1"></pageSetup><headerFooter differentFirst="false" differentOddEven="false"><oddHeader>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12&amp;A</oddHeader><oddFooter>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12Page &amp;P</oddFooter></headerFooter></worksheet>`
  203. c.Assert(output.String(), Equals, expectedXLSXSheet)
  204. }
  205. func (s *SheetSuite) TestSetColWidth(c *C) {
  206. file := NewFile()
  207. sheet, _ := file.AddSheet("Sheet1")
  208. _ = sheet.SetColWidth(0, 0, 10.5)
  209. _ = sheet.SetColWidth(1, 5, 11)
  210. c.Assert(sheet.Cols[0].Width, Equals, 10.5)
  211. c.Assert(sheet.Cols[0].Max, Equals, 1)
  212. c.Assert(sheet.Cols[0].Min, Equals, 1)
  213. c.Assert(sheet.Cols[1].Width, Equals, float64(11))
  214. c.Assert(sheet.Cols[1].Max, Equals, 2)
  215. c.Assert(sheet.Cols[1].Min, Equals, 2)
  216. }
  217. func (s *SheetSuite) TestSetRowHeightCM(c *C) {
  218. file := NewFile()
  219. sheet, _ := file.AddSheet("Sheet1")
  220. row := sheet.AddRow()
  221. row.SetHeightCM(1.5)
  222. c.Assert(row.Height, Equals, 42.51968505)
  223. }
  224. func (s *SheetSuite) TestAlignment(c *C) {
  225. leftalign := *DefaultAlignment()
  226. leftalign.Horizontal = "left"
  227. centerHalign := *DefaultAlignment()
  228. centerHalign.Horizontal = "center"
  229. rightalign := *DefaultAlignment()
  230. rightalign.Horizontal = "right"
  231. file := NewFile()
  232. sheet, _ := file.AddSheet("Sheet1")
  233. style := NewStyle()
  234. hrow := sheet.AddRow()
  235. // Horizontals
  236. cell := hrow.AddCell()
  237. cell.Value = "left"
  238. style.Alignment = leftalign
  239. style.ApplyAlignment = true
  240. cell.SetStyle(style)
  241. style = NewStyle()
  242. cell = hrow.AddCell()
  243. cell.Value = "centerH"
  244. style.Alignment = centerHalign
  245. style.ApplyAlignment = true
  246. cell.SetStyle(style)
  247. style = NewStyle()
  248. cell = hrow.AddCell()
  249. cell.Value = "right"
  250. style.Alignment = rightalign
  251. style.ApplyAlignment = true
  252. cell.SetStyle(style)
  253. // Verticals
  254. topalign := *DefaultAlignment()
  255. topalign.Vertical = "top"
  256. centerValign := *DefaultAlignment()
  257. centerValign.Vertical = "center"
  258. bottomalign := *DefaultAlignment()
  259. bottomalign.Vertical = "bottom"
  260. style = NewStyle()
  261. vrow := sheet.AddRow()
  262. cell = vrow.AddCell()
  263. cell.Value = "top"
  264. style.Alignment = topalign
  265. style.ApplyAlignment = true
  266. cell.SetStyle(style)
  267. style = NewStyle()
  268. cell = vrow.AddCell()
  269. cell.Value = "centerV"
  270. style.Alignment = centerValign
  271. style.ApplyAlignment = true
  272. cell.SetStyle(style)
  273. style = NewStyle()
  274. cell = vrow.AddCell()
  275. cell.Value = "bottom"
  276. style.Alignment = bottomalign
  277. style.ApplyAlignment = true
  278. cell.SetStyle(style)
  279. parts, err := file.MarshallParts()
  280. c.Assert(err, IsNil)
  281. obtained := parts["xl/styles.xml"]
  282. shouldbe := `<?xml version="1.0" encoding="UTF-8"?>
  283. <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="12"/><name val="Verdana"/><family val="0"/><charset val="0"/></font></fonts><fills count="2"><fill><patternFill patternType="none"><fgColor rgb="FFFFFFFF"/><bgColor rgb="00000000"/></patternFill></fill><fill><patternFill patternType="lightGray"/></fill></fills><borders count="1"><border><left style="none"></left><right style="none"></right><top style="none"></top><bottom style="none"></bottom></border></borders><cellXfs count="8"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="left" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="center" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="right" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="top" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="center" wrapText="0"/></xf><xf applyAlignment="1" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf></cellXfs></styleSheet>`
  284. expected := bytes.NewBufferString(shouldbe)
  285. c.Assert(obtained, Equals, expected.String())
  286. }
  287. func (s *SheetSuite) TestBorder(c *C) {
  288. file := NewFile()
  289. sheet, _ := file.AddSheet("Sheet1")
  290. row := sheet.AddRow()
  291. cell1 := row.AddCell()
  292. cell1.Value = "A cell!"
  293. style1 := NewStyle()
  294. style1.Border = *NewBorder("thin", "thin", "thin", "thin")
  295. style1.ApplyBorder = true
  296. cell1.SetStyle(style1)
  297. refTable := NewSharedStringRefTable()
  298. styles := newXlsxStyleSheet(nil)
  299. worksheet := sheet.makeXLSXSheet(refTable, styles)
  300. c.Assert(styles.Borders.Border[1].Left.Style, Equals, "thin")
  301. c.Assert(styles.Borders.Border[1].Right.Style, Equals, "thin")
  302. c.Assert(styles.Borders.Border[1].Top.Style, Equals, "thin")
  303. c.Assert(styles.Borders.Border[1].Bottom.Style, Equals, "thin")
  304. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 1)
  305. }
  306. func (s *SheetSuite) TestOutlineLevels(c *C) {
  307. file := NewFile()
  308. sheet, _ := file.AddSheet("Sheet1")
  309. r1 := sheet.AddRow()
  310. c11 := r1.AddCell()
  311. c11.Value = "A1"
  312. c12 := r1.AddCell()
  313. c12.Value = "B1"
  314. r2 := sheet.AddRow()
  315. c21 := r2.AddCell()
  316. c21.Value = "A2"
  317. c22 := r2.AddCell()
  318. c22.Value = "B2"
  319. r3 := sheet.AddRow()
  320. c31 := r3.AddCell()
  321. c31.Value = "A3"
  322. c32 := r3.AddCell()
  323. c32.Value = "B3"
  324. // Add some groups
  325. r1.OutlineLevel = 1
  326. r2.OutlineLevel = 2
  327. sheet.Col(0).OutlineLevel = 1
  328. refTable := NewSharedStringRefTable()
  329. styles := newXlsxStyleSheet(nil)
  330. worksheet := sheet.makeXLSXSheet(refTable, styles)
  331. c.Assert(worksheet.SheetFormatPr.OutlineLevelCol, Equals, uint8(1))
  332. c.Assert(worksheet.SheetFormatPr.OutlineLevelRow, Equals, uint8(2))
  333. c.Assert(worksheet.Cols.Col[0].OutlineLevel, Equals, uint8(1))
  334. c.Assert(worksheet.Cols.Col[1].OutlineLevel, Equals, uint8(0))
  335. c.Assert(worksheet.SheetData.Row[0].OutlineLevel, Equals, uint8(1))
  336. c.Assert(worksheet.SheetData.Row[1].OutlineLevel, Equals, uint8(2))
  337. c.Assert(worksheet.SheetData.Row[2].OutlineLevel, Equals, uint8(0))
  338. }
  339. func (s *SheetSuite) TestAutoFilter(c *C) {
  340. file := NewFile()
  341. sheet, _ := file.AddSheet("Sheet1")
  342. r1 := sheet.AddRow()
  343. r1.AddCell()
  344. r1.AddCell()
  345. r1.AddCell()
  346. r2 := sheet.AddRow()
  347. r2.AddCell()
  348. r2.AddCell()
  349. r2.AddCell()
  350. r3 := sheet.AddRow()
  351. r3.AddCell()
  352. r3.AddCell()
  353. r3.AddCell()
  354. // Define a filter area
  355. sheet.AutoFilter = &AutoFilter{TopLeftCell: "B2", BottomRightCell: "C3"}
  356. refTable := NewSharedStringRefTable()
  357. styles := newXlsxStyleSheet(nil)
  358. worksheet := sheet.makeXLSXSheet(refTable, styles)
  359. c.Assert(worksheet.AutoFilter, NotNil)
  360. c.Assert(worksheet.AutoFilter.Ref, Equals, "B2:C3")
  361. }