sheet_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. func (s *SheetSuite) TestMakeXLSXSheetFromRows(c *C) {
  19. file := NewFile()
  20. sheet, _ := file.AddSheet("Sheet1")
  21. row := sheet.AddRow()
  22. cell := row.AddCell()
  23. cell.Value = "A cell!"
  24. refTable := NewSharedStringRefTable()
  25. styles := newXlsxStyleSheet(nil)
  26. xSheet := sheet.makeXLSXSheet(refTable, styles)
  27. c.Assert(xSheet.Dimension.Ref, Equals, "A1")
  28. c.Assert(xSheet.SheetData.Row, HasLen, 1)
  29. xRow := xSheet.SheetData.Row[0]
  30. c.Assert(xRow.R, Equals, 1)
  31. c.Assert(xRow.Spans, Equals, "")
  32. c.Assert(xRow.C, HasLen, 1)
  33. xC := xRow.C[0]
  34. c.Assert(xC.R, Equals, "A1")
  35. c.Assert(xC.S, Equals, 0)
  36. c.Assert(xC.T, Equals, "s") // Shared string type
  37. c.Assert(xC.V, Equals, "0") // reference to shared string
  38. xSST := refTable.makeXLSXSST()
  39. c.Assert(xSST.Count, Equals, 1)
  40. c.Assert(xSST.UniqueCount, Equals, 1)
  41. c.Assert(xSST.SI, HasLen, 1)
  42. xSI := xSST.SI[0]
  43. c.Assert(xSI.T, Equals, "A cell!")
  44. }
  45. // Test if the NumFmts assigned properly according the FormatCode in cell.
  46. func (s *SheetSuite) TestMakeXLSXSheetWithNumFormats(c *C) {
  47. file := NewFile()
  48. sheet, _ := file.AddSheet("Sheet1")
  49. row := sheet.AddRow()
  50. cell1 := row.AddCell()
  51. cell1.Value = "A cell!"
  52. cell1.NumFmt = "general"
  53. cell2 := row.AddCell()
  54. cell2.Value = "37947.7500001"
  55. cell2.NumFmt = "0"
  56. cell3 := row.AddCell()
  57. cell3.Value = "37947.7500001"
  58. cell3.NumFmt = "mm-dd-yy"
  59. cell4 := row.AddCell()
  60. cell4.Value = "37947.7500001"
  61. cell4.NumFmt = "hh:mm:ss"
  62. refTable := NewSharedStringRefTable()
  63. styles := newXlsxStyleSheet(nil)
  64. worksheet := sheet.makeXLSXSheet(refTable, styles)
  65. c.Assert(styles.CellStyleXfs, IsNil)
  66. c.Assert(styles.CellXfs.Count, Equals, 5)
  67. c.Assert(styles.CellXfs.Xf[0].NumFmtId, Equals, 0)
  68. c.Assert(styles.CellXfs.Xf[1].NumFmtId, Equals, 0)
  69. c.Assert(styles.CellXfs.Xf[2].NumFmtId, Equals, 1)
  70. c.Assert(styles.CellXfs.Xf[3].NumFmtId, Equals, 14)
  71. c.Assert(styles.CellXfs.Xf[4].NumFmtId, Equals, 164)
  72. c.Assert(styles.NumFmts.Count, Equals, 1)
  73. c.Assert(styles.NumFmts.NumFmt[0].NumFmtId, Equals, 164)
  74. c.Assert(styles.NumFmts.NumFmt[0].FormatCode, Equals, "hh:mm:ss")
  75. // Finally we check that the cell points to the right CellXf /
  76. // CellStyleXf.
  77. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 1)
  78. c.Assert(worksheet.SheetData.Row[0].C[1].S, Equals, 2)
  79. }
  80. // When we create the xlsxSheet we also populate the xlsxStyles struct
  81. // with style information.
  82. func (s *SheetSuite) TestMakeXLSXSheetAlsoPopulatesXLSXSTyles(c *C) {
  83. file := NewFile()
  84. sheet, _ := file.AddSheet("Sheet1")
  85. row := sheet.AddRow()
  86. cell1 := row.AddCell()
  87. cell1.Value = "A cell!"
  88. style1 := NewStyle()
  89. style1.Font = *NewFont(10, "Verdana")
  90. style1.Fill = *NewFill("solid", "FFFFFFFF", "00000000")
  91. style1.Border = *NewBorder("none", "thin", "none", "thin")
  92. cell1.SetStyle(style1)
  93. // We need a second style to check that Xfs are populated correctly.
  94. cell2 := row.AddCell()
  95. cell2.Value = "Another cell!"
  96. style2 := NewStyle()
  97. style2.Font = *NewFont(10, "Verdana")
  98. style2.Fill = *NewFill("solid", "FFFFFFFF", "00000000")
  99. style2.Border = *NewBorder("none", "thin", "none", "thin")
  100. cell2.SetStyle(style2)
  101. refTable := NewSharedStringRefTable()
  102. styles := newXlsxStyleSheet(nil)
  103. worksheet := sheet.makeXLSXSheet(refTable, styles)
  104. c.Assert(styles.Fonts.Count, Equals, 2)
  105. c.Assert(styles.Fonts.Font[0].Sz.Val, Equals, "12")
  106. c.Assert(styles.Fonts.Font[0].Name.Val, Equals, "Verdana")
  107. c.Assert(styles.Fonts.Font[1].Sz.Val, Equals, "10")
  108. c.Assert(styles.Fonts.Font[1].Name.Val, Equals, "Verdana")
  109. c.Assert(styles.Fills.Count, Equals, 3)
  110. c.Assert(styles.Fills.Fill[0].PatternFill.PatternType, Equals, "none")
  111. c.Assert(styles.Fills.Fill[0].PatternFill.FgColor.RGB, Equals, "FFFFFFFF")
  112. c.Assert(styles.Fills.Fill[0].PatternFill.BgColor.RGB, Equals, "00000000")
  113. c.Assert(styles.Borders.Count, Equals, 2)
  114. c.Assert(styles.Borders.Border[1].Left.Style, Equals, "none")
  115. c.Assert(styles.Borders.Border[1].Right.Style, Equals, "thin")
  116. c.Assert(styles.Borders.Border[1].Top.Style, Equals, "none")
  117. c.Assert(styles.Borders.Border[1].Bottom.Style, Equals, "thin")
  118. c.Assert(styles.CellStyleXfs, IsNil)
  119. c.Assert(styles.CellXfs.Count, Equals, 2)
  120. c.Assert(styles.CellXfs.Xf[0].FontId, Equals, 0)
  121. c.Assert(styles.CellXfs.Xf[0].FillId, Equals, 0)
  122. c.Assert(styles.CellXfs.Xf[0].BorderId, Equals, 0)
  123. // Finally we check that the cell points to the right CellXf /
  124. // CellStyleXf.
  125. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 1)
  126. c.Assert(worksheet.SheetData.Row[0].C[1].S, Equals, 1)
  127. }
  128. // If the column width is not customised, the xslxCol.CustomWidth field is set to 0.
  129. func (s *SheetSuite) TestMakeXLSXSheetDefaultsCustomColWidth(c *C) {
  130. file := NewFile()
  131. sheet, _ := file.AddSheet("Sheet1")
  132. row := sheet.AddRow()
  133. cell1 := row.AddCell()
  134. cell1.Value = "A cell!"
  135. refTable := NewSharedStringRefTable()
  136. styles := newXlsxStyleSheet(nil)
  137. worksheet := sheet.makeXLSXSheet(refTable, styles)
  138. c.Assert(worksheet.Cols.Col[0].CustomWidth, Equals, false)
  139. }
  140. // If the column width is customised, the xslxCol.CustomWidth field is set to 1.
  141. func (s *SheetSuite) TestMakeXLSXSheetSetsCustomColWidth(c *C) {
  142. file := NewFile()
  143. sheet, _ := file.AddSheet("Sheet1")
  144. row := sheet.AddRow()
  145. cell1 := row.AddCell()
  146. cell1.Value = "A cell!"
  147. err := sheet.SetColWidth(0, 1, 10.5)
  148. c.Assert(err, IsNil)
  149. refTable := NewSharedStringRefTable()
  150. styles := newXlsxStyleSheet(nil)
  151. worksheet := sheet.makeXLSXSheet(refTable, styles)
  152. c.Assert(worksheet.Cols.Col[1].CustomWidth, Equals, true)
  153. }
  154. func (s *SheetSuite) TestMarshalSheet(c *C) {
  155. file := NewFile()
  156. sheet, _ := file.AddSheet("Sheet1")
  157. row := sheet.AddRow()
  158. cell := row.AddCell()
  159. cell.Value = "A cell!"
  160. refTable := NewSharedStringRefTable()
  161. styles := newXlsxStyleSheet(nil)
  162. xSheet := sheet.makeXLSXSheet(refTable, styles)
  163. output := bytes.NewBufferString(xml.Header)
  164. body, err := xml.Marshal(xSheet)
  165. c.Assert(err, IsNil)
  166. c.Assert(body, NotNil)
  167. _, err = output.Write(body)
  168. c.Assert(err, IsNil)
  169. expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
  170. <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>`
  171. c.Assert(output.String(), Equals, expectedXLSXSheet)
  172. }
  173. func (s *SheetSuite) TestMarshalSheetWithMultipleCells(c *C) {
  174. file := NewFile()
  175. sheet, _ := file.AddSheet("Sheet1")
  176. row := sheet.AddRow()
  177. cell := row.AddCell()
  178. cell.Value = "A cell (with value 1)!"
  179. cell = row.AddCell()
  180. cell.Value = "A cell (with value 2)!"
  181. refTable := NewSharedStringRefTable()
  182. styles := newXlsxStyleSheet(nil)
  183. xSheet := sheet.makeXLSXSheet(refTable, styles)
  184. output := bytes.NewBufferString(xml.Header)
  185. body, err := xml.Marshal(xSheet)
  186. c.Assert(err, IsNil)
  187. c.Assert(body, NotNil)
  188. _, err = output.Write(body)
  189. c.Assert(err, IsNil)
  190. expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
  191. <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>`
  192. c.Assert(output.String(), Equals, expectedXLSXSheet)
  193. }
  194. func (s *SheetSuite) TestSetColWidth(c *C) {
  195. file := NewFile()
  196. sheet, _ := file.AddSheet("Sheet1")
  197. _ = sheet.SetColWidth(0, 0, 10.5)
  198. _ = sheet.SetColWidth(1, 5, 11)
  199. c.Assert(sheet.Cols[0].Width, Equals, 10.5)
  200. c.Assert(sheet.Cols[0].Max, Equals, 1)
  201. c.Assert(sheet.Cols[0].Min, Equals, 1)
  202. c.Assert(sheet.Cols[1].Width, Equals, float64(11))
  203. c.Assert(sheet.Cols[1].Max, Equals, 6)
  204. c.Assert(sheet.Cols[1].Min, Equals, 2)
  205. }
  206. func (s *SheetSuite) TestSetRowHeightCM(c *C) {
  207. file := NewFile()
  208. sheet, _ := file.AddSheet("Sheet1")
  209. row := sheet.AddRow()
  210. row.SetHeightCM(1.5)
  211. c.Assert(row.Height, Equals, 42.51968505)
  212. }
  213. func (s *SheetSuite) TestAlignment(c *C) {
  214. leftalign := *DefaultAlignment()
  215. leftalign.Horizontal = "left"
  216. centerHalign := *DefaultAlignment()
  217. centerHalign.Horizontal = "center"
  218. rightalign := *DefaultAlignment()
  219. rightalign.Horizontal = "right"
  220. file := NewFile()
  221. sheet, _ := file.AddSheet("Sheet1")
  222. style := NewStyle()
  223. hrow := sheet.AddRow()
  224. // Horizontals
  225. cell := hrow.AddCell()
  226. cell.Value = "left"
  227. style.Alignment = leftalign
  228. style.ApplyAlignment = true
  229. cell.SetStyle(style)
  230. style = NewStyle()
  231. cell = hrow.AddCell()
  232. cell.Value = "centerH"
  233. style.Alignment = centerHalign
  234. style.ApplyAlignment = true
  235. cell.SetStyle(style)
  236. style = NewStyle()
  237. cell = hrow.AddCell()
  238. cell.Value = "right"
  239. style.Alignment = rightalign
  240. style.ApplyAlignment = true
  241. cell.SetStyle(style)
  242. // Verticals
  243. topalign := *DefaultAlignment()
  244. topalign.Vertical = "top"
  245. centerValign := *DefaultAlignment()
  246. centerValign.Vertical = "center"
  247. bottomalign := *DefaultAlignment()
  248. bottomalign.Vertical = "bottom"
  249. style = NewStyle()
  250. vrow := sheet.AddRow()
  251. cell = vrow.AddCell()
  252. cell.Value = "top"
  253. style.Alignment = topalign
  254. style.ApplyAlignment = true
  255. cell.SetStyle(style)
  256. style = NewStyle()
  257. cell = vrow.AddCell()
  258. cell.Value = "centerV"
  259. style.Alignment = centerValign
  260. style.ApplyAlignment = true
  261. cell.SetStyle(style)
  262. style = NewStyle()
  263. cell = vrow.AddCell()
  264. cell.Value = "bottom"
  265. style.Alignment = bottomalign
  266. style.ApplyAlignment = true
  267. cell.SetStyle(style)
  268. parts, err := file.MarshallParts()
  269. c.Assert(err, IsNil)
  270. obtained := parts["xl/styles.xml"]
  271. shouldbe := `<?xml version="1.0" encoding="UTF-8"?>
  272. <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>`
  273. expected := bytes.NewBufferString(shouldbe)
  274. c.Assert(obtained, Equals, expected.String())
  275. }
  276. func (s *SheetSuite) TestBorder(c *C) {
  277. file := NewFile()
  278. sheet, _ := file.AddSheet("Sheet1")
  279. row := sheet.AddRow()
  280. cell1 := row.AddCell()
  281. cell1.Value = "A cell!"
  282. style1 := NewStyle()
  283. style1.Border = *NewBorder("thin", "thin", "thin", "thin")
  284. style1.ApplyBorder = true
  285. cell1.SetStyle(style1)
  286. refTable := NewSharedStringRefTable()
  287. styles := newXlsxStyleSheet(nil)
  288. worksheet := sheet.makeXLSXSheet(refTable, styles)
  289. c.Assert(styles.Borders.Border[1].Left.Style, Equals, "thin")
  290. c.Assert(styles.Borders.Border[1].Right.Style, Equals, "thin")
  291. c.Assert(styles.Borders.Border[1].Top.Style, Equals, "thin")
  292. c.Assert(styles.Borders.Border[1].Bottom.Style, Equals, "thin")
  293. c.Assert(worksheet.SheetData.Row[0].C[0].S, Equals, 1)
  294. }
  295. func (s *SheetSuite) TestOutlineLevels(c *C) {
  296. file := NewFile()
  297. sheet, _ := file.AddSheet("Sheet1")
  298. r1 := sheet.AddRow()
  299. c11 := r1.AddCell()
  300. c11.Value = "A1"
  301. c12 := r1.AddCell()
  302. c12.Value = "B1"
  303. r2 := sheet.AddRow()
  304. c21 := r2.AddCell()
  305. c21.Value = "A2"
  306. c22 := r2.AddCell()
  307. c22.Value = "B2"
  308. r3 := sheet.AddRow()
  309. c31 := r3.AddCell()
  310. c31.Value = "A3"
  311. c32 := r3.AddCell()
  312. c32.Value = "B3"
  313. // Add some groups
  314. r1.OutlineLevel = 1
  315. r2.OutlineLevel = 2
  316. sheet.Col(0).OutlineLevel = 1
  317. refTable := NewSharedStringRefTable()
  318. styles := newXlsxStyleSheet(nil)
  319. worksheet := sheet.makeXLSXSheet(refTable, styles)
  320. c.Assert(worksheet.SheetFormatPr.OutlineLevelCol, Equals, uint8(1))
  321. c.Assert(worksheet.SheetFormatPr.OutlineLevelRow, Equals, uint8(2))
  322. c.Assert(worksheet.Cols.Col[0].OutlineLevel, Equals, uint8(1))
  323. c.Assert(worksheet.Cols.Col[1].OutlineLevel, Equals, uint8(0))
  324. c.Assert(worksheet.SheetData.Row[0].OutlineLevel, Equals, uint8(1))
  325. c.Assert(worksheet.SheetData.Row[1].OutlineLevel, Equals, uint8(2))
  326. c.Assert(worksheet.SheetData.Row[2].OutlineLevel, Equals, uint8(0))
  327. }
  328. func (s *SheetSuite) TestAutoFilter(c *C) {
  329. file := NewFile()
  330. sheet, _ := file.AddSheet("Sheet1")
  331. r1 := sheet.AddRow()
  332. r1.AddCell()
  333. r1.AddCell()
  334. r1.AddCell()
  335. r2 := sheet.AddRow()
  336. r2.AddCell()
  337. r2.AddCell()
  338. r2.AddCell()
  339. r3 := sheet.AddRow()
  340. r3.AddCell()
  341. r3.AddCell()
  342. r3.AddCell()
  343. // Define a filter area
  344. sheet.AutoFilter = &AutoFilter{TopLeftCell: "B2", BottomRightCell: "C3"}
  345. refTable := NewSharedStringRefTable()
  346. styles := newXlsxStyleSheet(nil)
  347. worksheet := sheet.makeXLSXSheet(refTable, styles)
  348. c.Assert(worksheet.AutoFilter, NotNil)
  349. c.Assert(worksheet.AutoFilter.Ref, Equals, "B2:C3")
  350. }