lib_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. package xlsx
  2. import (
  3. "bytes"
  4. "encoding/xml"
  5. // "strconv"
  6. . "gopkg.in/check.v1"
  7. "strings"
  8. )
  9. type LibSuite struct{}
  10. var _ = Suite(&LibSuite{})
  11. // Test that we can correctly extract a reference table from the
  12. // sharedStrings.xml file embedded in the XLSX file and return a
  13. // reference table of string values from it.
  14. func (l *LibSuite) TestReadSharedStringsFromZipFile(c *C) {
  15. var xlsxFile *File
  16. var err error
  17. xlsxFile, err = OpenFile("testfile.xlsx")
  18. c.Assert(err, IsNil)
  19. c.Assert(xlsxFile.referenceTable, NotNil)
  20. }
  21. // Helper function used to test contents of a given xlsxXf against
  22. // expectations.
  23. func testXf(c *C, result, expected *xlsxXf) {
  24. c.Assert(result.ApplyAlignment, Equals, expected.ApplyAlignment)
  25. c.Assert(result.ApplyBorder, Equals, expected.ApplyBorder)
  26. c.Assert(result.ApplyFont, Equals, expected.ApplyFont)
  27. c.Assert(result.ApplyFill, Equals, expected.ApplyFill)
  28. c.Assert(result.ApplyProtection, Equals, expected.ApplyProtection)
  29. c.Assert(result.BorderId, Equals, expected.BorderId)
  30. c.Assert(result.FillId, Equals, expected.FillId)
  31. c.Assert(result.FontId, Equals, expected.FontId)
  32. c.Assert(result.NumFmtId, Equals, expected.NumFmtId)
  33. }
  34. // We can correctly extract a style table from the style.xml file
  35. // embedded in the XLSX file and return a styles struct from it.
  36. func (l *LibSuite) TestReadStylesFromZipFile(c *C) {
  37. var xlsxFile *File
  38. var err error
  39. var fontCount, fillCount, borderCount, cellStyleXfCount, cellXfCount int
  40. var font xlsxFont
  41. var fill xlsxFill
  42. var border xlsxBorder
  43. var xf xlsxXf
  44. xlsxFile, err = OpenFile("testfile.xlsx")
  45. c.Assert(err, IsNil)
  46. c.Assert(xlsxFile.styles, NotNil)
  47. fontCount = len(xlsxFile.styles.Fonts)
  48. c.Assert(fontCount, Equals, 4)
  49. font = xlsxFile.styles.Fonts[0]
  50. c.Assert(font.Sz.Val, Equals, "11")
  51. c.Assert(font.Name.Val, Equals, "Calibri")
  52. fillCount = len(xlsxFile.styles.Fills)
  53. c.Assert(fillCount, Equals, 3)
  54. fill = xlsxFile.styles.Fills[2]
  55. c.Assert(fill.PatternFill.PatternType, Equals, "solid")
  56. borderCount = len(xlsxFile.styles.Borders)
  57. c.Assert(borderCount, Equals, 2)
  58. border = xlsxFile.styles.Borders[1]
  59. c.Assert(border.Left.Style, Equals, "thin")
  60. c.Assert(border.Right.Style, Equals, "thin")
  61. c.Assert(border.Top.Style, Equals, "thin")
  62. c.Assert(border.Bottom.Style, Equals, "thin")
  63. cellStyleXfCount = len(xlsxFile.styles.CellStyleXfs)
  64. c.Assert(cellStyleXfCount, Equals, 20)
  65. xf = xlsxFile.styles.CellStyleXfs[0]
  66. expectedXf := &xlsxXf{
  67. ApplyAlignment: true,
  68. ApplyBorder: true,
  69. ApplyFont: true,
  70. ApplyFill: false,
  71. ApplyProtection: true,
  72. BorderId: 0,
  73. FillId: 0,
  74. FontId: 0,
  75. NumFmtId: 164}
  76. testXf(c, &xf, expectedXf)
  77. cellXfCount = len(xlsxFile.styles.CellXfs)
  78. c.Assert(cellXfCount, Equals, 3)
  79. xf = xlsxFile.styles.CellXfs[0]
  80. expectedXf = &xlsxXf{
  81. ApplyAlignment: false,
  82. ApplyBorder: false,
  83. ApplyFont: false,
  84. ApplyFill: false,
  85. ApplyProtection: false,
  86. BorderId: 0,
  87. FillId: 0,
  88. FontId: 0,
  89. NumFmtId: 164}
  90. testXf(c, &xf, expectedXf)
  91. }
  92. // We can correctly extract a map of relationship Ids to the worksheet files in
  93. // which they are contained from the XLSX file.
  94. func (l *LibSuite) TestReadWorkbookRelationsFromZipFile(c *C) {
  95. var xlsxFile *File
  96. var err error
  97. xlsxFile, err = OpenFile("testfile.xlsx")
  98. c.Assert(err, IsNil)
  99. sheetCount := len(xlsxFile.Sheet)
  100. c.Assert(sheetCount, Equals, 3)
  101. }
  102. // which they are contained from the XLSX file, even when the
  103. // worksheet files have arbitrary, non-numeric names.
  104. func (l *LibSuite) TestReadWorkbookRelationsFromZipFileWithFunnyNames(c *C) {
  105. var xlsxFile *File
  106. var err error
  107. xlsxFile, err = OpenFile("testrels.xlsx")
  108. c.Assert(err, IsNil)
  109. sheetCount := len(xlsxFile.Sheet)
  110. c.Assert(sheetCount, Equals, 2)
  111. bob := xlsxFile.Sheet["Bob"]
  112. row1 := bob.Rows[0]
  113. cell1 := row1.Cells[0]
  114. c.Assert(cell1.String(), Equals, "I am Bob")
  115. }
  116. // Excel column codes are a special form of base26 that doesn't allow
  117. // zeros, except in the least significant part of the code. Test we
  118. // can smoosh the numbers in a normal base26 representation (presented
  119. // as a slice of integers) down to this form.
  120. func (l *LibSuite) TestSmooshBase26Slice(c *C) {
  121. input := []int{20, 0, 1}
  122. expected := []int{19, 26, 1}
  123. c.Assert(smooshBase26Slice(input), DeepEquals, expected)
  124. }
  125. // formatColumnName converts slices of base26 integers to alphabetical
  126. // column names. Note that the least signifcant character has a
  127. // different numeric offset (Yuck!)
  128. func (l *LibSuite) TestFormatColumnName(c *C) {
  129. c.Assert(formatColumnName([]int{0}), Equals, "A")
  130. c.Assert(formatColumnName([]int{25}), Equals, "Z")
  131. c.Assert(formatColumnName([]int{1, 25}), Equals, "AZ")
  132. c.Assert(formatColumnName([]int{26, 25}), Equals, "ZZ")
  133. c.Assert(formatColumnName([]int{26, 26, 25}), Equals, "ZZZ")
  134. }
  135. // getLargestDenominator returns the largest power of a provided value
  136. // that can fit within a given value.
  137. func (l *LibSuite) TestGetLargestDenominator(c *C) {
  138. d, p := getLargestDenominator(0, 1, 2, 0)
  139. c.Assert(d, Equals, 1)
  140. c.Assert(p, Equals, 0)
  141. d, p = getLargestDenominator(1, 1, 2, 0)
  142. c.Assert(d, Equals, 1)
  143. c.Assert(p, Equals, 0)
  144. d, p = getLargestDenominator(2, 1, 2, 0)
  145. c.Assert(d, Equals, 2)
  146. c.Assert(p, Equals, 1)
  147. d, p = getLargestDenominator(4, 1, 2, 0)
  148. c.Assert(d, Equals, 4)
  149. c.Assert(p, Equals, 2)
  150. d, p = getLargestDenominator(8, 1, 2, 0)
  151. c.Assert(d, Equals, 8)
  152. c.Assert(p, Equals, 3)
  153. d, p = getLargestDenominator(9, 1, 2, 0)
  154. c.Assert(d, Equals, 8)
  155. c.Assert(p, Equals, 3)
  156. d, p = getLargestDenominator(15,1, 2, 0)
  157. c.Assert(d, Equals, 8)
  158. c.Assert(p, Equals, 3)
  159. d, p = getLargestDenominator(16,1, 2, 0)
  160. c.Assert(d, Equals, 16)
  161. c.Assert(p, Equals, 4)
  162. }
  163. func (l *LibSuite) TestLettersToNumeric(c *C) {
  164. cases := map[string]int{"A": 0, "G": 6, "z": 25, "AA": 26, "Az": 51,
  165. "BA": 52, "BZ": 77, "ZA": 26*26 + 0, "ZZ": 26*26 + 25,
  166. "AAA": 26*26 + 26 + 0, "AMI": 1022}
  167. for input, ans := range cases {
  168. output := lettersToNumeric(input)
  169. c.Assert(output, Equals, ans)
  170. }
  171. }
  172. func (l *LibSuite) TestNumericToLetters(c *C) {
  173. cases := map[string]int{
  174. "A": 0,
  175. "G": 6,
  176. "Z": 25,
  177. "AA": 26,
  178. "AZ": 51,
  179. "BA": 52,
  180. "BZ": 77, "ZA": 26*26, "ZB": 26*26 + 1,
  181. "ZZ": 26*26 + 25,
  182. "AAA": 26*26 + 26 + 0, "AMI": 1022}
  183. for ans, input := range cases {
  184. output := numericToLetters(input)
  185. c.Assert(output, Equals, ans)
  186. }
  187. }
  188. func (l *LibSuite) TestLetterOnlyMapFunction(c *C) {
  189. var input string = "ABC123"
  190. var output string = strings.Map(letterOnlyMapF, input)
  191. c.Assert(output, Equals, "ABC")
  192. input = "abc123"
  193. output = strings.Map(letterOnlyMapF, input)
  194. c.Assert(output, Equals, "ABC")
  195. }
  196. func (l *LibSuite) TestIntOnlyMapFunction(c *C) {
  197. var input string = "ABC123"
  198. var output string = strings.Map(intOnlyMapF, input)
  199. c.Assert(output, Equals, "123")
  200. }
  201. func (l *LibSuite) TestGetCoordsFromCellIDString(c *C) {
  202. var cellIDString string = "A3"
  203. var x, y int
  204. var err error
  205. x, y, err = getCoordsFromCellIDString(cellIDString)
  206. c.Assert(err, IsNil)
  207. c.Assert(x, Equals, 0)
  208. c.Assert(y, Equals, 2)
  209. }
  210. func (l *LibSuite) TestGetCellIDStringFromCoords(c *C){
  211. c.Assert(getCellIDStringFromCoords(0, 0), Equals, "A1")
  212. c.Assert(getCellIDStringFromCoords(2, 2), Equals, "C3")
  213. }
  214. func (l *LibSuite) TestGetMaxMinFromDimensionRef(c *C) {
  215. var dimensionRef string = "A1:B2"
  216. var minx, miny, maxx, maxy int
  217. var err error
  218. minx, miny, maxx, maxy, err = getMaxMinFromDimensionRef(dimensionRef)
  219. c.Assert(err, IsNil)
  220. c.Assert(minx, Equals, 0)
  221. c.Assert(miny, Equals, 0)
  222. c.Assert(maxx, Equals, 1)
  223. c.Assert(maxy, Equals, 1)
  224. }
  225. func (l *LibSuite) TestGetRangeFromString(c *C) {
  226. var rangeString string
  227. var lower, upper int
  228. var err error
  229. rangeString = "1:3"
  230. lower, upper, err = getRangeFromString(rangeString)
  231. c.Assert(err, IsNil)
  232. c.Assert(lower, Equals, 1)
  233. c.Assert(upper, Equals, 3)
  234. }
  235. func (l *LibSuite) TestMakeRowFromSpan(c *C) {
  236. var rangeString string
  237. var row *Row
  238. var length int
  239. rangeString = "1:3"
  240. row = makeRowFromSpan(rangeString)
  241. length = len(row.Cells)
  242. c.Assert(length, Equals, 3)
  243. rangeString = "5:7" // Note - we ignore lower bound!
  244. row = makeRowFromSpan(rangeString)
  245. length = len(row.Cells)
  246. c.Assert(length, Equals, 7)
  247. rangeString = "1:1"
  248. row = makeRowFromSpan(rangeString)
  249. length = len(row.Cells)
  250. c.Assert(length, Equals, 1)
  251. }
  252. func (l *LibSuite) TestReadRowsFromSheet(c *C) {
  253. var sharedstringsXML = bytes.NewBufferString(`
  254. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  255. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4">
  256. <si>
  257. <t>Foo</t>
  258. </si>
  259. <si>
  260. <t>Bar</t>
  261. </si>
  262. <si>
  263. <t xml:space="preserve">Baz </t>
  264. </si>
  265. <si>
  266. <t>Quuk</t>
  267. </si>
  268. </sst>`)
  269. var sheetxml = bytes.NewBufferString(`
  270. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  271. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  272. xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  273. <dimension ref="A1:B2"/>
  274. <sheetViews>
  275. <sheetView tabSelected="1" workbookViewId="0">
  276. <selection activeCell="C2" sqref="C2"/>
  277. </sheetView>
  278. </sheetViews>
  279. <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
  280. <sheetData>
  281. <row r="1" spans="1:2">
  282. <c r="A1" t="s">
  283. <v>0</v>
  284. </c>
  285. <c r="B1" t="s">
  286. <v>1</v>
  287. </c>
  288. </row>
  289. <row r="2" spans="1:2">
  290. <c r="A2" t="s">
  291. <v>2</v>
  292. </c>
  293. <c r="B2" t="s">
  294. <v>3</v>
  295. </c>
  296. </row>
  297. </sheetData>
  298. <pageMargins left="0.7" right="0.7"
  299. top="0.78740157499999996"
  300. bottom="0.78740157499999996"
  301. header="0.3"
  302. footer="0.3"/>
  303. </worksheet>`)
  304. worksheet := new(xlsxWorksheet)
  305. err := xml.NewDecoder(sheetxml).Decode(worksheet)
  306. c.Assert(err, IsNil)
  307. sst := new(xlsxSST)
  308. err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  309. c.Assert(err, IsNil)
  310. file := new(File)
  311. file.referenceTable = MakeSharedStringRefTable(sst)
  312. rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  313. c.Assert(maxRows, Equals, 2)
  314. c.Assert(maxCols, Equals, 2)
  315. row := rows[0]
  316. c.Assert(len(row.Cells), Equals, 2)
  317. cell1 := row.Cells[0]
  318. c.Assert(cell1.String(), Equals, "Foo")
  319. cell2 := row.Cells[1]
  320. c.Assert(cell2.String(), Equals, "Bar")
  321. }
  322. func (l *LibSuite) TestReadRowsFromSheetWithLeadingEmptyRows(c *C) {
  323. var sharedstringsXML = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  324. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2"><si><t>ABC</t></si><si><t>DEF</t></si></sst>`)
  325. var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  326. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">
  327. <dimension ref="A4:A5"/>
  328. <sheetViews>
  329. <sheetView tabSelected="1" workbookViewId="0">
  330. <selection activeCell="A2" sqref="A2"/>
  331. </sheetView>
  332. </sheetViews>
  333. <sheetFormatPr baseColWidth="10" defaultRowHeight="15" x14ac:dyDescent="0"/>
  334. <sheetData>
  335. <row r="4" spans="1:1">
  336. <c r="A4" t="s">
  337. <v>0</v>
  338. </c>
  339. </row>
  340. <row r="5" spans="1:1">
  341. <c r="A5" t="s">
  342. <v>1</v>
  343. </c>
  344. </row>
  345. </sheetData>
  346. <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
  347. <pageSetup paperSize="9" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
  348. <extLst>
  349. <ext uri="{64002731-A6B0-56B0-2670-7721B7C09600}" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main">
  350. <mx:PLV Mode="0" OnePage="0" WScale="0"/>
  351. </ext>
  352. </extLst>
  353. </worksheet>
  354. `)
  355. worksheet := new(xlsxWorksheet)
  356. err := xml.NewDecoder(sheetxml).Decode(worksheet)
  357. c.Assert(err, IsNil)
  358. sst := new(xlsxSST)
  359. err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  360. c.Assert(err, IsNil)
  361. file := new(File)
  362. file.referenceTable = MakeSharedStringRefTable(sst)
  363. _, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  364. c.Assert(maxRows, Equals, 2)
  365. c.Assert(maxCols, Equals, 1)
  366. }
  367. func (l *LibSuite) TestReadRowsFromSheetWithEmptyCells(c *C) {
  368. var sharedstringsXML = bytes.NewBufferString(`
  369. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  370. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="8" uniqueCount="5">
  371. <si>
  372. <t>Bob</t>
  373. </si>
  374. <si>
  375. <t>Alice</t>
  376. </si>
  377. <si>
  378. <t>Sue</t>
  379. </si>
  380. <si>
  381. <t>Yes</t>
  382. </si>
  383. <si>
  384. <t>No</t>
  385. </si>
  386. </sst>
  387. `)
  388. var sheetxml = bytes.NewBufferString(`
  389. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  390. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:C3"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="D3" sqref="D3"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
  391. <sheetData>
  392. <row r="1" spans="1:3">
  393. <c r="A1" t="s">
  394. <v>
  395. 0
  396. </v>
  397. </c>
  398. <c r="B1" t="s">
  399. <v>
  400. 1
  401. </v>
  402. </c>
  403. <c r="C1" t="s">
  404. <v>
  405. 2
  406. </v>
  407. </c>
  408. </row>
  409. <row r="2" spans="1:3">
  410. <c r="A2" t="s">
  411. <v>
  412. 3
  413. </v>
  414. </c>
  415. <c r="B2" t="s">
  416. <v>
  417. 4
  418. </v>
  419. </c>
  420. <c r="C2" t="s">
  421. <v>
  422. 3
  423. </v>
  424. </c>
  425. </row>
  426. <row r="3" spans="1:3">
  427. <c r="A3" t="s">
  428. <v>
  429. 4
  430. </v>
  431. </c>
  432. <c r="C3" t="s">
  433. <v>
  434. 3
  435. </v>
  436. </c>
  437. </row>
  438. </sheetData>
  439. <pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/>
  440. </worksheet>
  441. `)
  442. worksheet := new(xlsxWorksheet)
  443. err := xml.NewDecoder(sheetxml).Decode(worksheet)
  444. c.Assert(err, IsNil)
  445. sst := new(xlsxSST)
  446. err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  447. c.Assert(err, IsNil)
  448. file := new(File)
  449. file.referenceTable = MakeSharedStringRefTable(sst)
  450. rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  451. c.Assert(maxRows, Equals, 3)
  452. c.Assert(maxCols, Equals, 3)
  453. row := rows[2]
  454. c.Assert(len(row.Cells), Equals, 3)
  455. cell1 := row.Cells[0]
  456. c.Assert(cell1.String(), Equals, "No")
  457. cell2 := row.Cells[1]
  458. c.Assert(cell2.String(), Equals, "")
  459. cell3 := row.Cells[2]
  460. c.Assert(cell3.String(), Equals, "Yes")
  461. }
  462. func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
  463. var row *Row
  464. var cell1, cell2, cell3, cell4 *Cell
  465. var sharedstringsXML = bytes.NewBufferString(`
  466. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  467. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4"><si><t>A</t></si><si><t>B</t></si><si><t>C</t></si><si><t>D</t></si></sst>`)
  468. var sheetxml = bytes.NewBufferString(`
  469. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  470. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:D8"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="A7" sqref="A7"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:4"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c><c r="C1" t="s"><v>2</v></c><c r="D1" t="s"><v>3</v></c></row><row r="2" spans="1:4"><c r="A2"><v>1</v></c></row><row r="3" spans="1:4"><c r="B3"><v>1</v></c></row><row r="4" spans="1:4"><c r="C4"><v>1</v></c></row><row r="5" spans="1:4"><c r="D5"><v>1</v></c></row><row r="6" spans="1:4"><c r="C6"><v>1</v></c></row><row r="7" spans="1:4"><c r="B7"><v>1</v></c></row><row r="8" spans="1:4"><c r="A8"><v>1</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>
  471. `)
  472. worksheet := new(xlsxWorksheet)
  473. err := xml.NewDecoder(sheetxml).Decode(worksheet)
  474. c.Assert(err, IsNil)
  475. sst := new(xlsxSST)
  476. err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  477. c.Assert(err, IsNil)
  478. file := new(File)
  479. file.referenceTable = MakeSharedStringRefTable(sst)
  480. rows, maxCol, maxRow := readRowsFromSheet(worksheet, file)
  481. c.Assert(maxCol, Equals, 4)
  482. c.Assert(maxRow, Equals, 8)
  483. row = rows[0]
  484. c.Assert(len(row.Cells), Equals, 4)
  485. cell1 = row.Cells[0]
  486. c.Assert(cell1.String(), Equals, "A")
  487. cell2 = row.Cells[1]
  488. c.Assert(cell2.String(), Equals, "B")
  489. cell3 = row.Cells[2]
  490. c.Assert(cell3.String(), Equals, "C")
  491. cell4 = row.Cells[3]
  492. c.Assert(cell4.String(), Equals, "D")
  493. row = rows[1]
  494. c.Assert(len(row.Cells), Equals, 4)
  495. cell1 = row.Cells[0]
  496. c.Assert(cell1.String(), Equals, "1")
  497. cell2 = row.Cells[1]
  498. c.Assert(cell2.String(), Equals, "")
  499. cell3 = row.Cells[2]
  500. c.Assert(cell3.String(), Equals, "")
  501. cell4 = row.Cells[3]
  502. c.Assert(cell4.String(), Equals, "")
  503. }