lib_test.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package xlsx
  2. import (
  3. // "bytes"
  4. // "encoding/xml"
  5. // "strconv"
  6. "strings"
  7. . "gopkg.in/check.v1"
  8. )
  9. type LibSuite struct {}
  10. var _ = Suite(&LibSuite{})
  11. // Test we can correctly open a XSLX file and return a xlsx.File
  12. // struct.
  13. func (l *LibSuite) TestOpenFile(c *C) {
  14. var xlsxFile *File
  15. var error error
  16. xlsxFile, error = OpenFile("testfile.xlsx")
  17. c.Assert(error, IsNil)
  18. c.Assert(xlsxFile, NotNil)
  19. }
  20. // Test that when we open a real XLSX file we create xlsx.Sheet
  21. // objects for the sheets inside the file and that these sheets are
  22. // themselves correct.
  23. func (l *LibSuite) TestCreateSheet(c *C) {
  24. var xlsxFile *File
  25. var err error
  26. var sheet *Sheet
  27. var row *Row
  28. xlsxFile, err = OpenFile("testfile.xlsx")
  29. c.Assert(err, IsNil)
  30. c.Assert(xlsxFile, NotNil)
  31. sheetLen := len(xlsxFile.Sheets)
  32. c.Assert(sheetLen, Equals, 3)
  33. sheet = xlsxFile.Sheets[0]
  34. rowLen := len(sheet.Rows)
  35. c.Assert(rowLen, Equals, 2)
  36. row = sheet.Rows[0]
  37. c.Assert(len(row.Cells), Equals, 2)
  38. cell := row.Cells[0]
  39. cellstring := cell.String()
  40. c.Assert(cellstring, Equals, "Foo")
  41. }
  42. // Test that GetStyle correctly converts the xlsxStyle.Fonts.
  43. func (l *LibSuite) TestGetStyleWithFonts(c *C) {
  44. var cell *Cell
  45. var style *Style
  46. var xStyles *xlsxStyles
  47. var fonts []xlsxFont
  48. var cellXfs []xlsxXf
  49. fonts = make([]xlsxFont, 1)
  50. fonts[0] = xlsxFont{
  51. Sz: xlsxVal{Val: "10"},
  52. Name: xlsxVal{Val: "Calibra"}}
  53. cellXfs = make([]xlsxXf, 1)
  54. cellXfs[0] = xlsxXf{ApplyFont: true, FontId: 0}
  55. xStyles = &xlsxStyles{Fonts: fonts, CellXfs: cellXfs}
  56. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  57. style = cell.GetStyle()
  58. c.Assert(style, NotNil)
  59. c.Assert(style.Font.Size, Equals, 10)
  60. c.Assert(style.Font.Name, Equals, "Calibra")
  61. }
  62. // Test that GetStyle correctly converts the xlsxStyle.Fills.
  63. func (l *LibSuite) TestGetStyleWithFills(c *C) {
  64. var cell *Cell
  65. var style *Style
  66. var xStyles *xlsxStyles
  67. var fills []xlsxFill
  68. var cellXfs []xlsxXf
  69. fills = make([]xlsxFill, 1)
  70. fills[0] = xlsxFill{
  71. PatternFill: xlsxPatternFill{
  72. PatternType: "solid",
  73. FgColor: xlsxColor{RGB: "FF000000"},
  74. BgColor: xlsxColor{RGB: "00FF0000"}}}
  75. cellXfs = make([]xlsxXf, 1)
  76. cellXfs[0] = xlsxXf{ApplyFill: true, FillId: 0}
  77. xStyles = &xlsxStyles{Fills: fills, CellXfs: cellXfs}
  78. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  79. style = cell.GetStyle()
  80. fill := style.Fill
  81. c.Assert(fill.PatternType, Equals, "solid")
  82. c.Assert(fill.BgColor, Equals, "00FF0000")
  83. c.Assert(fill.FgColor, Equals, "FF000000")
  84. }
  85. // Test that GetStyle correctly converts the xlsxStyle.Borders.
  86. func (l *LibSuite) TestGetStyleWithBorders(c *C) {
  87. var cell *Cell
  88. var style *Style
  89. var xStyles *xlsxStyles
  90. var borders []xlsxBorder
  91. var cellXfs []xlsxXf
  92. borders = make([]xlsxBorder, 1)
  93. borders[0] = xlsxBorder{
  94. Left: xlsxLine{Style: "thin"},
  95. Right: xlsxLine{Style: "thin"},
  96. Top: xlsxLine{Style: "thin"},
  97. Bottom: xlsxLine{Style: "thin"}}
  98. cellXfs = make([]xlsxXf, 1)
  99. cellXfs[0] = xlsxXf{ApplyBorder: true, BorderId: 0}
  100. xStyles = &xlsxStyles{Borders: borders, CellXfs: cellXfs}
  101. cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
  102. style = cell.GetStyle()
  103. border := style.Border
  104. c.Assert(border.Left, Equals, "thin")
  105. c.Assert(border.Right, Equals, "thin")
  106. c.Assert(border.Top, Equals, "thin")
  107. c.Assert(border.Bottom, Equals, "thin")
  108. }
  109. // Test that we can correctly extract a reference table from the
  110. // sharedStrings.xml file embedded in the XLSX file and return a
  111. // reference table of string values from it.
  112. func (l *LibSuite) TestReadSharedStringsFromZipFile(c *C) {
  113. var xlsxFile *File
  114. var err error
  115. xlsxFile, err = OpenFile("testfile.xlsx")
  116. c.Assert(err, IsNil)
  117. c.Assert(xlsxFile.referenceTable, NotNil)
  118. }
  119. // Helper function used to test contents of a given xlsxXf against
  120. // expectations.
  121. func testXf(c *C, result, expected *xlsxXf) {
  122. c.Assert(result.ApplyAlignment, Equals, expected.ApplyAlignment)
  123. c.Assert(result.ApplyBorder, Equals, expected.ApplyBorder)
  124. c.Assert(result.ApplyFont, Equals, expected.ApplyFont)
  125. c.Assert(result.ApplyFill, Equals, expected.ApplyFill)
  126. c.Assert(result.ApplyProtection, Equals, expected.ApplyProtection)
  127. c.Assert(result.BorderId, Equals, expected.BorderId)
  128. c.Assert(result.FillId, Equals, expected.FillId)
  129. c.Assert(result.FontId, Equals, expected.FontId)
  130. c.Assert(result.NumFmtId, Equals, expected.NumFmtId)
  131. }
  132. // We can correctly extract a style table from the style.xml file
  133. // embedded in the XLSX file and return a styles struct from it.
  134. func (l *LibSuite) TestReadStylesFromZipFile(c *C) {
  135. var xlsxFile *File
  136. var err error
  137. var fontCount, fillCount, borderCount, cellStyleXfCount, cellXfCount int
  138. var font xlsxFont
  139. var fill xlsxFill
  140. var border xlsxBorder
  141. var xf xlsxXf
  142. xlsxFile, err = OpenFile("testfile.xlsx")
  143. c.Assert(err, IsNil)
  144. c.Assert(xlsxFile.styles, NotNil)
  145. fontCount = len(xlsxFile.styles.Fonts)
  146. c.Assert(fontCount, Equals, 4)
  147. font = xlsxFile.styles.Fonts[0]
  148. c.Assert(font.Sz.Val, Equals, "11")
  149. c.Assert(font.Name.Val, Equals, "Calibri")
  150. fillCount = len(xlsxFile.styles.Fills)
  151. c.Assert(fillCount, Equals, 3)
  152. fill = xlsxFile.styles.Fills[2]
  153. c.Assert(fill.PatternFill.PatternType, Equals, "solid")
  154. borderCount = len(xlsxFile.styles.Borders)
  155. c.Assert(borderCount, Equals, 2)
  156. border = xlsxFile.styles.Borders[1]
  157. c.Assert(border.Left.Style, Equals, "thin")
  158. c.Assert(border.Right.Style, Equals, "thin")
  159. c.Assert(border.Top.Style, Equals, "thin")
  160. c.Assert(border.Bottom.Style, Equals, "thin")
  161. cellStyleXfCount = len(xlsxFile.styles.CellStyleXfs)
  162. c.Assert(cellStyleXfCount, Equals, 20)
  163. xf = xlsxFile.styles.CellStyleXfs[0]
  164. expectedXf := &xlsxXf{
  165. ApplyAlignment: true,
  166. ApplyBorder: true,
  167. ApplyFont: true,
  168. ApplyFill: false,
  169. ApplyProtection: true,
  170. BorderId: 0,
  171. FillId: 0,
  172. FontId: 0,
  173. NumFmtId: 164}
  174. testXf(c, &xf, expectedXf)
  175. cellXfCount = len(xlsxFile.styles.CellXfs)
  176. c.Assert(cellXfCount, Equals, 3)
  177. xf = xlsxFile.styles.CellXfs[0]
  178. expectedXf = &xlsxXf{
  179. ApplyAlignment: false,
  180. ApplyBorder: false,
  181. ApplyFont: false,
  182. ApplyFill: false,
  183. ApplyProtection: false,
  184. BorderId: 0,
  185. FillId: 0,
  186. FontId: 0,
  187. NumFmtId: 164}
  188. testXf(c, &xf, expectedXf)
  189. }
  190. // We can correctly extract a map of relationship Ids to the worksheet files in
  191. // which they are contained from the XLSX file.
  192. func (l *LibSuite) TestReadWorkbookRelationsFromZipFile(c *C) {
  193. var xlsxFile *File
  194. var err error
  195. xlsxFile, err = OpenFile("testfile.xlsx")
  196. c.Assert(err, IsNil)
  197. sheetCount := len(xlsxFile.Sheet)
  198. c.Assert(sheetCount, Equals, 3)
  199. }
  200. // which they are contained from the XLSX file, even when the
  201. // worksheet files have arbitrary, non-numeric names.
  202. func (l *LibSuite) TestReadWorkbookRelationsFromZipFileWithFunnyNames(c *C) {
  203. var xlsxFile *File
  204. var err error
  205. xlsxFile, err = OpenFile("testrels.xlsx")
  206. c.Assert(err, IsNil)
  207. sheetCount := len(xlsxFile.Sheet)
  208. c.Assert(sheetCount, Equals, 2)
  209. bob := xlsxFile.Sheet["Bob"]
  210. row1 := bob.Rows[0]
  211. cell1 := row1.Cells[0]
  212. c.Assert(cell1.String(), Equals, "I am Bob")
  213. }
  214. func (l *LibSuite) TestLettersToNumeric(c *C) {
  215. cases := map[string]int{"A": 0, "G": 6, "z": 25, "AA": 26, "Az": 51,
  216. "BA": 52, "Bz": 77, "ZA": 26*26 + 0, "ZZ": 26*26 + 25,
  217. "AAA": 26*26 + 26 + 0, "AMI": 1022}
  218. for input, ans := range cases {
  219. output := lettersToNumeric(input)
  220. c.Assert(output, Equals, ans)
  221. }
  222. }
  223. func (l *LibSuite) TestLetterOnlyMapFunction(c *C) {
  224. var input string = "ABC123"
  225. var output string = strings.Map(letterOnlyMapF, input)
  226. c.Assert(output, Equals, "ABC")
  227. input = "abc123"
  228. output = strings.Map(letterOnlyMapF, input)
  229. c.Assert(output, Equals, "ABC")
  230. }
  231. func (l *LibSuite) TestIntOnlyMapFunction(c *C) {
  232. var input string = "ABC123"
  233. var output string = strings.Map(intOnlyMapF, input)
  234. c.Assert(output, Equals, "123")
  235. }
  236. func (l *LibSuite) TestGetCoordsFromCellIDString(c *C) {
  237. var cellIDString string = "A3"
  238. var x, y int
  239. var err error
  240. x, y, err = getCoordsFromCellIDString(cellIDString)
  241. c.Assert(err, IsNil)
  242. c.Assert(x, Equals, 0)
  243. c.Assert(y, Equals, 2)
  244. }
  245. func (l *LibSuite) TestGetMaxMinFromDimensionRef(c *C) {
  246. var dimensionRef string = "A1:B2"
  247. var minx, miny, maxx, maxy int
  248. var err error
  249. minx, miny, maxx, maxy, err = getMaxMinFromDimensionRef(dimensionRef)
  250. c.Assert(err, IsNil)
  251. c.Assert(minx, Equals, 0)
  252. c.Assert(miny, Equals, 0)
  253. c.Assert(maxx, Equals, 1)
  254. c.Assert(maxy, Equals, 1)
  255. }
  256. // func (l *LibSuite) TestGetRangeFromString(c *C) {
  257. // var rangeString string
  258. // var lower, upper int
  259. // var err error
  260. // rangeString = "1:3"
  261. // lower, upper, err = getRangeFromString(rangeString)
  262. // if err != nil {
  263. // t.Error(err)
  264. // }
  265. // if lower != 1 {
  266. // t.Error("Expected lower bound == 1, but got ", strconv.Itoa(lower))
  267. // }
  268. // if upper != 3 {
  269. // t.Error("Expected upper bound == 3, but got ", strconv.Itoa(upper))
  270. // }
  271. // }
  272. // func (l *LibSuite) TestMakeRowFromSpan(c *C) {
  273. // var rangeString string
  274. // var row *Row
  275. // var length int
  276. // rangeString = "1:3"
  277. // row = makeRowFromSpan(rangeString)
  278. // length = len(row.Cells)
  279. // if length != 3 {
  280. // t.Error("Expected a row with 3 cells, but got ", strconv.Itoa(length))
  281. // }
  282. // rangeString = "5:7" // Note - we ignore lower bound!
  283. // row = makeRowFromSpan(rangeString)
  284. // length = len(row.Cells)
  285. // if length != 7 {
  286. // t.Error("Expected a row with 7 cells, but got ", strconv.Itoa(length))
  287. // }
  288. // rangeString = "1:1"
  289. // row = makeRowFromSpan(rangeString)
  290. // length = len(row.Cells)
  291. // if length != 1 {
  292. // t.Error("Expected a row with 1 cells, but got ", strconv.Itoa(length))
  293. // }
  294. // }
  295. // func (l *LibSuite) TestReadRowsFromSheet(c *C) {
  296. // var sharedstringsXML = bytes.NewBufferString(`
  297. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  298. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4">
  299. // <si>
  300. // <t>Foo</t>
  301. // </si>
  302. // <si>
  303. // <t>Bar</t>
  304. // </si>
  305. // <si>
  306. // <t xml:space="preserve">Baz </t>
  307. // </si>
  308. // <si>
  309. // <t>Quuk</t>
  310. // </si>
  311. // </sst>`)
  312. // var sheetxml = bytes.NewBufferString(`
  313. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  314. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  315. // xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  316. // <dimension ref="A1:B2"/>
  317. // <sheetViews>
  318. // <sheetView tabSelected="1" workbookViewId="0">
  319. // <selection activeCell="C2" sqref="C2"/>
  320. // </sheetView>
  321. // </sheetViews>
  322. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
  323. // <sheetData>
  324. // <row r="1" spans="1:2">
  325. // <c r="A1" t="s">
  326. // <v>0</v>
  327. // </c>
  328. // <c r="B1" t="s">
  329. // <v>1</v>
  330. // </c>
  331. // </row>
  332. // <row r="2" spans="1:2">
  333. // <c r="A2" t="s">
  334. // <v>2</v>
  335. // </c>
  336. // <c r="B2" t="s">
  337. // <v>3</v>
  338. // </c>
  339. // </row>
  340. // </sheetData>
  341. // <pageMargins left="0.7" right="0.7"
  342. // top="0.78740157499999996"
  343. // bottom="0.78740157499999996"
  344. // header="0.3"
  345. // footer="0.3"/>
  346. // </worksheet>`)
  347. // worksheet := new(xlsxWorksheet)
  348. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  349. // if err != nil {
  350. // t.Error(err.Error())
  351. // return
  352. // }
  353. // sst := new(xlsxSST)
  354. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  355. // if err != nil {
  356. // t.Error(err.Error())
  357. // return
  358. // }
  359. // file := new(File)
  360. // file.referenceTable = MakeSharedStringRefTable(sst)
  361. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  362. // if maxRows != 2 {
  363. // t.Error("Expected maxRows == 2")
  364. // }
  365. // if maxCols != 2 {
  366. // t.Error("Expected maxCols == 2")
  367. // }
  368. // row := rows[0]
  369. // if len(row.Cells) != 2 {
  370. // t.Error("Expected len(row.Cells) == 2, got ", strconv.Itoa(len(row.Cells)))
  371. // }
  372. // cell1 := row.Cells[0]
  373. // if cell1.String() != "Foo" {
  374. // t.Error("Expected cell1.String() == 'Foo', got ", cell1.String())
  375. // }
  376. // cell2 := row.Cells[1]
  377. // if cell2.String() != "Bar" {
  378. // t.Error("Expected cell2.String() == 'Bar', got ", cell2.String())
  379. // }
  380. // }
  381. // func (l *LibSuite) TestReadRowsFromSheetWithLeadingEmptyRows(c *C) {
  382. // var sharedstringsXML = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  383. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2"><si><t>ABC</t></si><si><t>DEF</t></si></sst>`)
  384. // var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  385. // <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">
  386. // <dimension ref="A4:A5"/>
  387. // <sheetViews>
  388. // <sheetView tabSelected="1" workbookViewId="0">
  389. // <selection activeCell="A2" sqref="A2"/>
  390. // </sheetView>
  391. // </sheetViews>
  392. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15" x14ac:dyDescent="0"/>
  393. // <sheetData>
  394. // <row r="4" spans="1:1">
  395. // <c r="A4" t="s">
  396. // <v>0</v>
  397. // </c>
  398. // </row>
  399. // <row r="5" spans="1:1">
  400. // <c r="A5" t="s">
  401. // <v>1</v>
  402. // </c>
  403. // </row>
  404. // </sheetData>
  405. // <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
  406. // <pageSetup paperSize="9" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
  407. // <extLst>
  408. // <ext uri="{64002731-A6B0-56B0-2670-7721B7C09600}" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main">
  409. // <mx:PLV Mode="0" OnePage="0" WScale="0"/>
  410. // </ext>
  411. // </extLst>
  412. // </worksheet>
  413. // `)
  414. // worksheet := new(xlsxWorksheet)
  415. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  416. // if err != nil {
  417. // t.Error(err.Error())
  418. // return
  419. // }
  420. // sst := new(xlsxSST)
  421. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  422. // if err != nil {
  423. // t.Error(err.Error())
  424. // return
  425. // }
  426. // file := new(File)
  427. // file.referenceTable = MakeSharedStringRefTable(sst)
  428. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  429. // if maxRows != 2 {
  430. // t.Error("Expected maxRows == 2, got ", strconv.Itoa(len(rows)))
  431. // }
  432. // if maxCols != 1 {
  433. // t.Error("Expected maxCols == 1, got ", strconv.Itoa(maxCols))
  434. // }
  435. // }
  436. // func (l *LibSuite) TestReadRowsFromSheetWithEmptyCells(c *C) {
  437. // var sharedstringsXML = bytes.NewBufferString(`
  438. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  439. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="8" uniqueCount="5">
  440. // <si>
  441. // <t>Bob</t>
  442. // </si>
  443. // <si>
  444. // <t>Alice</t>
  445. // </si>
  446. // <si>
  447. // <t>Sue</t>
  448. // </si>
  449. // <si>
  450. // <t>Yes</t>
  451. // </si>
  452. // <si>
  453. // <t>No</t>
  454. // </si>
  455. // </sst>
  456. // `)
  457. // var sheetxml = bytes.NewBufferString(`
  458. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  459. // <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"/>
  460. // <sheetData>
  461. // <row r="1" spans="1:3">
  462. // <c r="A1" t="s">
  463. // <v>
  464. // 0
  465. // </v>
  466. // </c>
  467. // <c r="B1" t="s">
  468. // <v>
  469. // 1
  470. // </v>
  471. // </c>
  472. // <c r="C1" t="s">
  473. // <v>
  474. // 2
  475. // </v>
  476. // </c>
  477. // </row>
  478. // <row r="2" spans="1:3">
  479. // <c r="A2" t="s">
  480. // <v>
  481. // 3
  482. // </v>
  483. // </c>
  484. // <c r="B2" t="s">
  485. // <v>
  486. // 4
  487. // </v>
  488. // </c>
  489. // <c r="C2" t="s">
  490. // <v>
  491. // 3
  492. // </v>
  493. // </c>
  494. // </row>
  495. // <row r="3" spans="1:3">
  496. // <c r="A3" t="s">
  497. // <v>
  498. // 4
  499. // </v>
  500. // </c>
  501. // <c r="C3" t="s">
  502. // <v>
  503. // 3
  504. // </v>
  505. // </c>
  506. // </row>
  507. // </sheetData>
  508. // <pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/>
  509. // </worksheet>
  510. // `)
  511. // worksheet := new(xlsxWorksheet)
  512. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  513. // if err != nil {
  514. // t.Error(err.Error())
  515. // return
  516. // }
  517. // sst := new(xlsxSST)
  518. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  519. // if err != nil {
  520. // t.Error(err.Error())
  521. // return
  522. // }
  523. // file := new(File)
  524. // file.referenceTable = MakeSharedStringRefTable(sst)
  525. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  526. // if maxRows != 3 {
  527. // t.Error("Expected maxRows == 3, got ", strconv.Itoa(len(rows)))
  528. // }
  529. // if maxCols != 3 {
  530. // t.Error("Expected maxCols == 3, got ", strconv.Itoa(maxCols))
  531. // }
  532. // row := rows[2]
  533. // if len(row.Cells) != 3 {
  534. // t.Error("Expected len(row.Cells) == 3, got ", strconv.Itoa(len(row.Cells)))
  535. // }
  536. // cell1 := row.Cells[0]
  537. // if cell1.String() != "No" {
  538. // t.Error("Expected cell1.String() == 'No', got ", cell1.String())
  539. // }
  540. // cell2 := row.Cells[1]
  541. // if cell2.String() != "" {
  542. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  543. // }
  544. // cell3 := row.Cells[2]
  545. // if cell3.String() != "Yes" {
  546. // t.Error("Expected cell3.String() == 'Yes', got ", cell3.String())
  547. // }
  548. // }
  549. // func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
  550. // var row *Row
  551. // var cell1, cell2, cell3, cell4 *Cell
  552. // var sharedstringsXML = bytes.NewBufferString(`
  553. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  554. // <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>`)
  555. // var sheetxml = bytes.NewBufferString(`
  556. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  557. // <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>
  558. // `)
  559. // worksheet := new(xlsxWorksheet)
  560. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  561. // if err != nil {
  562. // t.Error(err.Error())
  563. // return
  564. // }
  565. // sst := new(xlsxSST)
  566. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  567. // if err != nil {
  568. // t.Error(err.Error())
  569. // return
  570. // }
  571. // file := new(File)
  572. // file.referenceTable = MakeSharedStringRefTable(sst)
  573. // rows, maxCol, maxRow := readRowsFromSheet(worksheet, file)
  574. // if maxCol != 4 {
  575. // t.Error("Expected maxCol == 4, got ", strconv.Itoa(maxCol))
  576. // }
  577. // if maxRow != 8 {
  578. // t.Error("Expected maxRow == 8, got ", strconv.Itoa(maxRow))
  579. // }
  580. // row = rows[0]
  581. // if len(row.Cells) != 4 {
  582. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  583. // }
  584. // cell1 = row.Cells[0]
  585. // if cell1.String() != "A" {
  586. // t.Error("Expected cell1.String() == 'A', got ", cell1.String())
  587. // }
  588. // cell2 = row.Cells[1]
  589. // if cell2.String() != "B" {
  590. // t.Error("Expected cell2.String() == 'B', got ", cell2.String())
  591. // }
  592. // cell3 = row.Cells[2]
  593. // if cell3.String() != "C" {
  594. // t.Error("Expected cell3.String() == 'C', got ", cell3.String())
  595. // }
  596. // cell4 = row.Cells[3]
  597. // if cell4.String() != "D" {
  598. // t.Error("Expected cell4.String() == 'D', got ", cell4.String())
  599. // }
  600. // row = rows[1]
  601. // if len(row.Cells) != 4 {
  602. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  603. // }
  604. // cell1 = row.Cells[0]
  605. // if cell1.String() != "1" {
  606. // t.Error("Expected cell1.String() == '1', got ", cell1.String())
  607. // }
  608. // cell2 = row.Cells[1]
  609. // if cell2.String() != "" {
  610. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  611. // }
  612. // cell3 = row.Cells[2]
  613. // if cell3.String() != "" {
  614. // t.Error("Expected cell3.String() == '', got ", cell3.String())
  615. // }
  616. // cell4 = row.Cells[3]
  617. // if cell4.String() != "" {
  618. // t.Error("Expected cell4.String() == '', got ", cell4.String())
  619. // }
  620. // }