lib_test.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. // if err != nil {
  207. // t.Error(err.Error())
  208. // return
  209. // }
  210. // sheetCount := len(xlsxFile.Sheet)
  211. // if sheetCount != 2 {
  212. // t.Error("Expected 3 items in xlsxFile.Sheet, but found ", strconv.Itoa(sheetCount))
  213. // }
  214. // bob := xlsxFile.Sheet["Bob"]
  215. // row1 := bob.Rows[0]
  216. // cell1 := row1.Cells[0]
  217. // if cell1.String() != "I am Bob" {
  218. // t.Error("Expected cell1.String() == 'I am Bob', but got '" + cell1.String() + "'")
  219. // }
  220. // }
  221. // func (l *LibSuite) TestLettersToNumeric(c *C) {
  222. // cases := map[string]int{"A": 0, "G": 6, "z": 25, "AA": 26, "Az": 51,
  223. // "BA": 52, "Bz": 77, "ZA": 26*26 + 0, "ZZ": 26*26 + 25,
  224. // "AAA": 26*26 + 26 + 0, "AMI": 1022}
  225. // for input, ans := range cases {
  226. // output := lettersToNumeric(input)
  227. // if output != ans {
  228. // t.Error("Expected output '"+input+"' == ", ans,
  229. // "but got ", strconv.Itoa(output))
  230. // }
  231. // }
  232. // }
  233. // func (l *LibSuite) TestLetterOnlyMapFunction(c *C) {
  234. // var input string = "ABC123"
  235. // var output string = strings.Map(letterOnlyMapF, input)
  236. // if output != "ABC" {
  237. // t.Error("Expected output == 'ABC' but got ", output)
  238. // }
  239. // input = "abc123"
  240. // output = strings.Map(letterOnlyMapF, input)
  241. // if output != "ABC" {
  242. // t.Error("Expected output == 'ABC' but got ", output)
  243. // }
  244. // }
  245. // func (l *LibSuite) TestIntOnlyMapFunction(c *C) {
  246. // var input string = "ABC123"
  247. // var output string = strings.Map(intOnlyMapF, input)
  248. // if output != "123" {
  249. // t.Error("Expected output == '123' but got ", output)
  250. // }
  251. // }
  252. // func (l *LibSuite) TestGetCoordsFromCellIDString(c *C) {
  253. // var cellIDString string = "A3"
  254. // var x, y int
  255. // var err error
  256. // x, y, err = getCoordsFromCellIDString(cellIDString)
  257. // if err != nil {
  258. // t.Error(err)
  259. // }
  260. // if x != 0 {
  261. // t.Error("Expected x == 0, but got ", strconv.Itoa(x))
  262. // }
  263. // if y != 2 {
  264. // t.Error("Expected y == 2, but got ", strconv.Itoa(y))
  265. // }
  266. // }
  267. // func (l *LibSuite) TestGetMaxMinFromDimensionRef(c *C) {
  268. // var dimensionRef string = "A1:B2"
  269. // var minx, miny, maxx, maxy int
  270. // var err error
  271. // minx, miny, maxx, maxy, err = getMaxMinFromDimensionRef(dimensionRef)
  272. // if err != nil {
  273. // t.Error(err)
  274. // }
  275. // if minx != 0 {
  276. // t.Error("Expected minx == 0, but got ", strconv.Itoa(minx))
  277. // }
  278. // if miny != 0 {
  279. // t.Error("Expected miny == 0, but got ", strconv.Itoa(miny))
  280. // }
  281. // if maxx != 1 {
  282. // t.Error("Expected maxx == 0, but got ", strconv.Itoa(maxx))
  283. // }
  284. // if maxy != 1 {
  285. // t.Error("Expected maxy == 0, but got ", strconv.Itoa(maxy))
  286. // }
  287. // }
  288. // func (l *LibSuite) TestGetRangeFromString(c *C) {
  289. // var rangeString string
  290. // var lower, upper int
  291. // var err error
  292. // rangeString = "1:3"
  293. // lower, upper, err = getRangeFromString(rangeString)
  294. // if err != nil {
  295. // t.Error(err)
  296. // }
  297. // if lower != 1 {
  298. // t.Error("Expected lower bound == 1, but got ", strconv.Itoa(lower))
  299. // }
  300. // if upper != 3 {
  301. // t.Error("Expected upper bound == 3, but got ", strconv.Itoa(upper))
  302. // }
  303. // }
  304. // func (l *LibSuite) TestMakeRowFromSpan(c *C) {
  305. // var rangeString string
  306. // var row *Row
  307. // var length int
  308. // rangeString = "1:3"
  309. // row = makeRowFromSpan(rangeString)
  310. // length = len(row.Cells)
  311. // if length != 3 {
  312. // t.Error("Expected a row with 3 cells, but got ", strconv.Itoa(length))
  313. // }
  314. // rangeString = "5:7" // Note - we ignore lower bound!
  315. // row = makeRowFromSpan(rangeString)
  316. // length = len(row.Cells)
  317. // if length != 7 {
  318. // t.Error("Expected a row with 7 cells, but got ", strconv.Itoa(length))
  319. // }
  320. // rangeString = "1:1"
  321. // row = makeRowFromSpan(rangeString)
  322. // length = len(row.Cells)
  323. // if length != 1 {
  324. // t.Error("Expected a row with 1 cells, but got ", strconv.Itoa(length))
  325. // }
  326. // }
  327. // func (l *LibSuite) TestReadRowsFromSheet(c *C) {
  328. // var sharedstringsXML = bytes.NewBufferString(`
  329. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  330. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4">
  331. // <si>
  332. // <t>Foo</t>
  333. // </si>
  334. // <si>
  335. // <t>Bar</t>
  336. // </si>
  337. // <si>
  338. // <t xml:space="preserve">Baz </t>
  339. // </si>
  340. // <si>
  341. // <t>Quuk</t>
  342. // </si>
  343. // </sst>`)
  344. // var sheetxml = bytes.NewBufferString(`
  345. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  346. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  347. // xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  348. // <dimension ref="A1:B2"/>
  349. // <sheetViews>
  350. // <sheetView tabSelected="1" workbookViewId="0">
  351. // <selection activeCell="C2" sqref="C2"/>
  352. // </sheetView>
  353. // </sheetViews>
  354. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
  355. // <sheetData>
  356. // <row r="1" spans="1:2">
  357. // <c r="A1" t="s">
  358. // <v>0</v>
  359. // </c>
  360. // <c r="B1" t="s">
  361. // <v>1</v>
  362. // </c>
  363. // </row>
  364. // <row r="2" spans="1:2">
  365. // <c r="A2" t="s">
  366. // <v>2</v>
  367. // </c>
  368. // <c r="B2" t="s">
  369. // <v>3</v>
  370. // </c>
  371. // </row>
  372. // </sheetData>
  373. // <pageMargins left="0.7" right="0.7"
  374. // top="0.78740157499999996"
  375. // bottom="0.78740157499999996"
  376. // header="0.3"
  377. // footer="0.3"/>
  378. // </worksheet>`)
  379. // worksheet := new(xlsxWorksheet)
  380. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  381. // if err != nil {
  382. // t.Error(err.Error())
  383. // return
  384. // }
  385. // sst := new(xlsxSST)
  386. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  387. // if err != nil {
  388. // t.Error(err.Error())
  389. // return
  390. // }
  391. // file := new(File)
  392. // file.referenceTable = MakeSharedStringRefTable(sst)
  393. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  394. // if maxRows != 2 {
  395. // t.Error("Expected maxRows == 2")
  396. // }
  397. // if maxCols != 2 {
  398. // t.Error("Expected maxCols == 2")
  399. // }
  400. // row := rows[0]
  401. // if len(row.Cells) != 2 {
  402. // t.Error("Expected len(row.Cells) == 2, got ", strconv.Itoa(len(row.Cells)))
  403. // }
  404. // cell1 := row.Cells[0]
  405. // if cell1.String() != "Foo" {
  406. // t.Error("Expected cell1.String() == 'Foo', got ", cell1.String())
  407. // }
  408. // cell2 := row.Cells[1]
  409. // if cell2.String() != "Bar" {
  410. // t.Error("Expected cell2.String() == 'Bar', got ", cell2.String())
  411. // }
  412. // }
  413. // func (l *LibSuite) TestReadRowsFromSheetWithLeadingEmptyRows(c *C) {
  414. // var sharedstringsXML = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  415. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2"><si><t>ABC</t></si><si><t>DEF</t></si></sst>`)
  416. // var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  417. // <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">
  418. // <dimension ref="A4:A5"/>
  419. // <sheetViews>
  420. // <sheetView tabSelected="1" workbookViewId="0">
  421. // <selection activeCell="A2" sqref="A2"/>
  422. // </sheetView>
  423. // </sheetViews>
  424. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15" x14ac:dyDescent="0"/>
  425. // <sheetData>
  426. // <row r="4" spans="1:1">
  427. // <c r="A4" t="s">
  428. // <v>0</v>
  429. // </c>
  430. // </row>
  431. // <row r="5" spans="1:1">
  432. // <c r="A5" t="s">
  433. // <v>1</v>
  434. // </c>
  435. // </row>
  436. // </sheetData>
  437. // <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
  438. // <pageSetup paperSize="9" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
  439. // <extLst>
  440. // <ext uri="{64002731-A6B0-56B0-2670-7721B7C09600}" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main">
  441. // <mx:PLV Mode="0" OnePage="0" WScale="0"/>
  442. // </ext>
  443. // </extLst>
  444. // </worksheet>
  445. // `)
  446. // worksheet := new(xlsxWorksheet)
  447. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  448. // if err != nil {
  449. // t.Error(err.Error())
  450. // return
  451. // }
  452. // sst := new(xlsxSST)
  453. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  454. // if err != nil {
  455. // t.Error(err.Error())
  456. // return
  457. // }
  458. // file := new(File)
  459. // file.referenceTable = MakeSharedStringRefTable(sst)
  460. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  461. // if maxRows != 2 {
  462. // t.Error("Expected maxRows == 2, got ", strconv.Itoa(len(rows)))
  463. // }
  464. // if maxCols != 1 {
  465. // t.Error("Expected maxCols == 1, got ", strconv.Itoa(maxCols))
  466. // }
  467. // }
  468. // func (l *LibSuite) TestReadRowsFromSheetWithEmptyCells(c *C) {
  469. // var sharedstringsXML = bytes.NewBufferString(`
  470. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  471. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="8" uniqueCount="5">
  472. // <si>
  473. // <t>Bob</t>
  474. // </si>
  475. // <si>
  476. // <t>Alice</t>
  477. // </si>
  478. // <si>
  479. // <t>Sue</t>
  480. // </si>
  481. // <si>
  482. // <t>Yes</t>
  483. // </si>
  484. // <si>
  485. // <t>No</t>
  486. // </si>
  487. // </sst>
  488. // `)
  489. // var sheetxml = bytes.NewBufferString(`
  490. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  491. // <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"/>
  492. // <sheetData>
  493. // <row r="1" spans="1:3">
  494. // <c r="A1" t="s">
  495. // <v>
  496. // 0
  497. // </v>
  498. // </c>
  499. // <c r="B1" t="s">
  500. // <v>
  501. // 1
  502. // </v>
  503. // </c>
  504. // <c r="C1" t="s">
  505. // <v>
  506. // 2
  507. // </v>
  508. // </c>
  509. // </row>
  510. // <row r="2" spans="1:3">
  511. // <c r="A2" t="s">
  512. // <v>
  513. // 3
  514. // </v>
  515. // </c>
  516. // <c r="B2" t="s">
  517. // <v>
  518. // 4
  519. // </v>
  520. // </c>
  521. // <c r="C2" t="s">
  522. // <v>
  523. // 3
  524. // </v>
  525. // </c>
  526. // </row>
  527. // <row r="3" spans="1:3">
  528. // <c r="A3" t="s">
  529. // <v>
  530. // 4
  531. // </v>
  532. // </c>
  533. // <c r="C3" t="s">
  534. // <v>
  535. // 3
  536. // </v>
  537. // </c>
  538. // </row>
  539. // </sheetData>
  540. // <pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/>
  541. // </worksheet>
  542. // `)
  543. // worksheet := new(xlsxWorksheet)
  544. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  545. // if err != nil {
  546. // t.Error(err.Error())
  547. // return
  548. // }
  549. // sst := new(xlsxSST)
  550. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  551. // if err != nil {
  552. // t.Error(err.Error())
  553. // return
  554. // }
  555. // file := new(File)
  556. // file.referenceTable = MakeSharedStringRefTable(sst)
  557. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  558. // if maxRows != 3 {
  559. // t.Error("Expected maxRows == 3, got ", strconv.Itoa(len(rows)))
  560. // }
  561. // if maxCols != 3 {
  562. // t.Error("Expected maxCols == 3, got ", strconv.Itoa(maxCols))
  563. // }
  564. // row := rows[2]
  565. // if len(row.Cells) != 3 {
  566. // t.Error("Expected len(row.Cells) == 3, got ", strconv.Itoa(len(row.Cells)))
  567. // }
  568. // cell1 := row.Cells[0]
  569. // if cell1.String() != "No" {
  570. // t.Error("Expected cell1.String() == 'No', got ", cell1.String())
  571. // }
  572. // cell2 := row.Cells[1]
  573. // if cell2.String() != "" {
  574. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  575. // }
  576. // cell3 := row.Cells[2]
  577. // if cell3.String() != "Yes" {
  578. // t.Error("Expected cell3.String() == 'Yes', got ", cell3.String())
  579. // }
  580. // }
  581. // func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
  582. // var row *Row
  583. // var cell1, cell2, cell3, cell4 *Cell
  584. // var sharedstringsXML = bytes.NewBufferString(`
  585. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  586. // <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>`)
  587. // var sheetxml = bytes.NewBufferString(`
  588. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  589. // <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>
  590. // `)
  591. // worksheet := new(xlsxWorksheet)
  592. // err := xml.NewDecoder(sheetxml).Decode(worksheet)
  593. // if err != nil {
  594. // t.Error(err.Error())
  595. // return
  596. // }
  597. // sst := new(xlsxSST)
  598. // err = xml.NewDecoder(sharedstringsXML).Decode(sst)
  599. // if err != nil {
  600. // t.Error(err.Error())
  601. // return
  602. // }
  603. // file := new(File)
  604. // file.referenceTable = MakeSharedStringRefTable(sst)
  605. // rows, maxCol, maxRow := readRowsFromSheet(worksheet, file)
  606. // if maxCol != 4 {
  607. // t.Error("Expected maxCol == 4, got ", strconv.Itoa(maxCol))
  608. // }
  609. // if maxRow != 8 {
  610. // t.Error("Expected maxRow == 8, got ", strconv.Itoa(maxRow))
  611. // }
  612. // row = rows[0]
  613. // if len(row.Cells) != 4 {
  614. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  615. // }
  616. // cell1 = row.Cells[0]
  617. // if cell1.String() != "A" {
  618. // t.Error("Expected cell1.String() == 'A', got ", cell1.String())
  619. // }
  620. // cell2 = row.Cells[1]
  621. // if cell2.String() != "B" {
  622. // t.Error("Expected cell2.String() == 'B', got ", cell2.String())
  623. // }
  624. // cell3 = row.Cells[2]
  625. // if cell3.String() != "C" {
  626. // t.Error("Expected cell3.String() == 'C', got ", cell3.String())
  627. // }
  628. // cell4 = row.Cells[3]
  629. // if cell4.String() != "D" {
  630. // t.Error("Expected cell4.String() == 'D', got ", cell4.String())
  631. // }
  632. // row = rows[1]
  633. // if len(row.Cells) != 4 {
  634. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  635. // }
  636. // cell1 = row.Cells[0]
  637. // if cell1.String() != "1" {
  638. // t.Error("Expected cell1.String() == '1', got ", cell1.String())
  639. // }
  640. // cell2 = row.Cells[1]
  641. // if cell2.String() != "" {
  642. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  643. // }
  644. // cell3 = row.Cells[2]
  645. // if cell3.String() != "" {
  646. // t.Error("Expected cell3.String() == '', got ", cell3.String())
  647. // }
  648. // cell4 = row.Cells[3]
  649. // if cell4.String() != "" {
  650. // t.Error("Expected cell4.String() == '', got ", cell4.String())
  651. // }
  652. // }