lib_test.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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 error error
  115. // xlsxFile, error = OpenFile("testfile.xlsx")
  116. // if error != nil {
  117. // t.Error(error.Error())
  118. // return
  119. // }
  120. // if xlsxFile.referenceTable == nil {
  121. // t.Error("expected non nil xlsxFile.referenceTable")
  122. // return
  123. // }
  124. // }
  125. // func testXf(t *testing.T, result, expected *xlsxXf) {
  126. // if result.ApplyAlignment != expected.ApplyAlignment {
  127. // t.Error("Expected result.ApplyAlignment == ", expected.ApplyAlignment,
  128. // ", got", result.ApplyAlignment)
  129. // return
  130. // }
  131. // if result.ApplyBorder != expected.ApplyBorder {
  132. // t.Error("Expected result.ApplyBorder == ", expected.ApplyBorder,
  133. // ", got ", result.ApplyBorder)
  134. // return
  135. // }
  136. // if result.ApplyFont != expected.ApplyFont {
  137. // t.Error("Expect result.ApplyFont == ", expected.ApplyFont,
  138. // ", got ", result.ApplyFont)
  139. // return
  140. // }
  141. // if result.ApplyFill != expected.ApplyFill {
  142. // t.Error("Expected result.ApplyFill == ", expected.ApplyFill,
  143. // ", got ", result.ApplyFill)
  144. // return
  145. // }
  146. // if result.ApplyProtection != expected.ApplyProtection {
  147. // t.Error("Expexcted result.ApplyProtection == ", expected.ApplyProtection,
  148. // ", got ", result.ApplyProtection)
  149. // return
  150. // }
  151. // if result.BorderId != expected.BorderId {
  152. // t.Error("Expected BorderId == ", expected.BorderId,
  153. // ". got ", result.BorderId)
  154. // return
  155. // }
  156. // if result.FillId != expected.FillId {
  157. // t.Error("Expected result.FillId == ", expected.FillId,
  158. // ", got ", result.FillId)
  159. // return
  160. // }
  161. // if result.FontId != expected.FontId {
  162. // t.Error("Expected result.FontId == ", expected.FontId,
  163. // ", got ", result.FontId)
  164. // return
  165. // }
  166. // if result.NumFmtId != expected.NumFmtId {
  167. // t.Error("Expected result.NumFmtId == ", expected.NumFmtId,
  168. // ", got ", result.NumFmtId)
  169. // return
  170. // }
  171. // }
  172. // // We can correctly extract a style table from the style.xml file
  173. // // embedded in the XLSX file and return a styles struct from it.
  174. // func (l *LibSuite) TestReadStylesFromZipFile(c *C) {
  175. // var xlsxFile *File
  176. // var error error
  177. // var fontCount, fillCount, borderCount, cellStyleXfCount, cellXfCount int
  178. // var font xlsxFont
  179. // var fill xlsxFill
  180. // var border xlsxBorder
  181. // var xf xlsxXf
  182. // xlsxFile, error = OpenFile("testfile.xlsx")
  183. // if error != nil {
  184. // t.Error(error.Error())
  185. // return
  186. // }
  187. // if xlsxFile.styles == nil {
  188. // t.Error("expected non nil xlsxFile.styles")
  189. // return
  190. // }
  191. // fontCount = len(xlsxFile.styles.Fonts)
  192. // if fontCount != 4 {
  193. // t.Error("expected exactly 4 xslxFonts, got ", fontCount)
  194. // return
  195. // }
  196. // font = xlsxFile.styles.Fonts[0]
  197. // if font.Sz.Val != "11" {
  198. // t.Error("expected font.Sz.Val == 11, got ", font.Sz.Val)
  199. // return
  200. // }
  201. // if font.Name.Val != "Calibri" {
  202. // t.Error("expected font.Name.Val == 'Calibri', got ", font.Name.Val)
  203. // return
  204. // }
  205. // fillCount = len(xlsxFile.styles.Fills)
  206. // if fillCount != 3 {
  207. // t.Error("Expected exactly 3 xlsxFills, got ", fillCount)
  208. // return
  209. // }
  210. // fill = xlsxFile.styles.Fills[2]
  211. // if fill.PatternFill.PatternType != "solid" {
  212. // t.Error("Expected PatternFill.PatternType == 'solid', but got ",
  213. // fill.PatternFill.PatternType)
  214. // return
  215. // }
  216. // borderCount = len(xlsxFile.styles.Borders)
  217. // if borderCount != 2 {
  218. // t.Error("Expected exactly 2 xlsxBorders, got ", borderCount)
  219. // return
  220. // }
  221. // border = xlsxFile.styles.Borders[1]
  222. // if border.Left.Style != "thin" {
  223. // t.Error("Expected border.Left.Style == 'thin', got ", border.Left.Style)
  224. // return
  225. // }
  226. // if border.Right.Style != "thin" {
  227. // t.Error("Expected border.Right.Style == 'thin', got ", border.Right.Style)
  228. // return
  229. // }
  230. // if border.Top.Style != "thin" {
  231. // t.Error("Expected border.Top.Style == 'thin', got ", border.Top.Style)
  232. // return
  233. // }
  234. // if border.Bottom.Style != "thin" {
  235. // t.Error("Expected border.Bottom.Style == 'thin', got ", border.Bottom.Style)
  236. // return
  237. // }
  238. // cellStyleXfCount = len(xlsxFile.styles.CellStyleXfs)
  239. // if cellStyleXfCount != 20 {
  240. // t.Error("Expected excactly 20 cellStyleXfs, got ", cellStyleXfCount)
  241. // return
  242. // }
  243. // xf = xlsxFile.styles.CellStyleXfs[0]
  244. // expectedXf := &xlsxXf{
  245. // ApplyAlignment: true,
  246. // ApplyBorder: true,
  247. // ApplyFont: true,
  248. // ApplyFill: false,
  249. // ApplyProtection: true,
  250. // BorderId: 0,
  251. // FillId: 0,
  252. // FontId: 0,
  253. // NumFmtId: 164}
  254. // testXf(t, &xf, expectedXf)
  255. // cellXfCount = len(xlsxFile.styles.CellXfs)
  256. // if cellXfCount != 3 {
  257. // t.Error("Expected excactly 3 cellXfs, got ", cellXfCount)
  258. // return
  259. // }
  260. // xf = xlsxFile.styles.CellXfs[0]
  261. // expectedXf = &xlsxXf{
  262. // ApplyAlignment: false,
  263. // ApplyBorder: false,
  264. // ApplyFont: false,
  265. // ApplyFill: false,
  266. // ApplyProtection: false,
  267. // BorderId: 0,
  268. // FillId: 0,
  269. // FontId: 0,
  270. // NumFmtId: 164}
  271. // testXf(t, &xf, expectedXf)
  272. // }
  273. // // We can correctly extract a map of relationship Ids to the worksheet files in
  274. // // which they are contained from the XLSX file.
  275. // func (l *LibSuite) TestReadWorkbookRelationsFromZipFile(c *C) {
  276. // var xlsxFile *File
  277. // var error error
  278. // xlsxFile, error = OpenFile("testfile.xlsx")
  279. // if error != nil {
  280. // t.Error(error.Error())
  281. // return
  282. // }
  283. // sheetCount := len(xlsxFile.Sheet)
  284. // if sheetCount != 3 {
  285. // t.Error("Expected 3 items in xlsxFile.Sheet, but found ", strconv.Itoa(sheetCount))
  286. // }
  287. // }
  288. // // We can extract a map of relationship Ids to the worksheet files in
  289. // // which they are contained from the XLSX file, even when the
  290. // // worksheet files have arbitrary, non-numeric names.
  291. // func (l *LibSuite) TestReadWorkbookRelationsFromZipFileWithFunnyNames(c *C) {
  292. // var xlsxFile *File
  293. // var error error
  294. // xlsxFile, error = OpenFile("testrels.xlsx")
  295. // if error != nil {
  296. // t.Error(error.Error())
  297. // return
  298. // }
  299. // sheetCount := len(xlsxFile.Sheet)
  300. // if sheetCount != 2 {
  301. // t.Error("Expected 3 items in xlsxFile.Sheet, but found ", strconv.Itoa(sheetCount))
  302. // }
  303. // bob := xlsxFile.Sheet["Bob"]
  304. // row1 := bob.Rows[0]
  305. // cell1 := row1.Cells[0]
  306. // if cell1.String() != "I am Bob" {
  307. // t.Error("Expected cell1.String() == 'I am Bob', but got '" + cell1.String() + "'")
  308. // }
  309. // }
  310. // func (l *LibSuite) TestLettersToNumeric(c *C) {
  311. // cases := map[string]int{"A": 0, "G": 6, "z": 25, "AA": 26, "Az": 51,
  312. // "BA": 52, "Bz": 77, "ZA": 26*26 + 0, "ZZ": 26*26 + 25,
  313. // "AAA": 26*26 + 26 + 0, "AMI": 1022}
  314. // for input, ans := range cases {
  315. // output := lettersToNumeric(input)
  316. // if output != ans {
  317. // t.Error("Expected output '"+input+"' == ", ans,
  318. // "but got ", strconv.Itoa(output))
  319. // }
  320. // }
  321. // }
  322. // func (l *LibSuite) TestLetterOnlyMapFunction(c *C) {
  323. // var input string = "ABC123"
  324. // var output string = strings.Map(letterOnlyMapF, input)
  325. // if output != "ABC" {
  326. // t.Error("Expected output == 'ABC' but got ", output)
  327. // }
  328. // input = "abc123"
  329. // output = strings.Map(letterOnlyMapF, input)
  330. // if output != "ABC" {
  331. // t.Error("Expected output == 'ABC' but got ", output)
  332. // }
  333. // }
  334. // func (l *LibSuite) TestIntOnlyMapFunction(c *C) {
  335. // var input string = "ABC123"
  336. // var output string = strings.Map(intOnlyMapF, input)
  337. // if output != "123" {
  338. // t.Error("Expected output == '123' but got ", output)
  339. // }
  340. // }
  341. // func (l *LibSuite) TestGetCoordsFromCellIDString(c *C) {
  342. // var cellIDString string = "A3"
  343. // var x, y int
  344. // var error error
  345. // x, y, error = getCoordsFromCellIDString(cellIDString)
  346. // if error != nil {
  347. // t.Error(error)
  348. // }
  349. // if x != 0 {
  350. // t.Error("Expected x == 0, but got ", strconv.Itoa(x))
  351. // }
  352. // if y != 2 {
  353. // t.Error("Expected y == 2, but got ", strconv.Itoa(y))
  354. // }
  355. // }
  356. // func (l *LibSuite) TestGetMaxMinFromDimensionRef(c *C) {
  357. // var dimensionRef string = "A1:B2"
  358. // var minx, miny, maxx, maxy int
  359. // var err error
  360. // minx, miny, maxx, maxy, err = getMaxMinFromDimensionRef(dimensionRef)
  361. // if err != nil {
  362. // t.Error(err)
  363. // }
  364. // if minx != 0 {
  365. // t.Error("Expected minx == 0, but got ", strconv.Itoa(minx))
  366. // }
  367. // if miny != 0 {
  368. // t.Error("Expected miny == 0, but got ", strconv.Itoa(miny))
  369. // }
  370. // if maxx != 1 {
  371. // t.Error("Expected maxx == 0, but got ", strconv.Itoa(maxx))
  372. // }
  373. // if maxy != 1 {
  374. // t.Error("Expected maxy == 0, but got ", strconv.Itoa(maxy))
  375. // }
  376. // }
  377. // func (l *LibSuite) TestGetRangeFromString(c *C) {
  378. // var rangeString string
  379. // var lower, upper int
  380. // var error error
  381. // rangeString = "1:3"
  382. // lower, upper, error = getRangeFromString(rangeString)
  383. // if error != nil {
  384. // t.Error(error)
  385. // }
  386. // if lower != 1 {
  387. // t.Error("Expected lower bound == 1, but got ", strconv.Itoa(lower))
  388. // }
  389. // if upper != 3 {
  390. // t.Error("Expected upper bound == 3, but got ", strconv.Itoa(upper))
  391. // }
  392. // }
  393. // func (l *LibSuite) TestMakeRowFromSpan(c *C) {
  394. // var rangeString string
  395. // var row *Row
  396. // var length int
  397. // rangeString = "1:3"
  398. // row = makeRowFromSpan(rangeString)
  399. // length = len(row.Cells)
  400. // if length != 3 {
  401. // t.Error("Expected a row with 3 cells, but got ", strconv.Itoa(length))
  402. // }
  403. // rangeString = "5:7" // Note - we ignore lower bound!
  404. // row = makeRowFromSpan(rangeString)
  405. // length = len(row.Cells)
  406. // if length != 7 {
  407. // t.Error("Expected a row with 7 cells, but got ", strconv.Itoa(length))
  408. // }
  409. // rangeString = "1:1"
  410. // row = makeRowFromSpan(rangeString)
  411. // length = len(row.Cells)
  412. // if length != 1 {
  413. // t.Error("Expected a row with 1 cells, but got ", strconv.Itoa(length))
  414. // }
  415. // }
  416. // func (l *LibSuite) TestReadRowsFromSheet(c *C) {
  417. // var sharedstringsXML = bytes.NewBufferString(`
  418. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  419. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4">
  420. // <si>
  421. // <t>Foo</t>
  422. // </si>
  423. // <si>
  424. // <t>Bar</t>
  425. // </si>
  426. // <si>
  427. // <t xml:space="preserve">Baz </t>
  428. // </si>
  429. // <si>
  430. // <t>Quuk</t>
  431. // </si>
  432. // </sst>`)
  433. // var sheetxml = bytes.NewBufferString(`
  434. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  435. // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  436. // xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  437. // <dimension ref="A1:B2"/>
  438. // <sheetViews>
  439. // <sheetView tabSelected="1" workbookViewId="0">
  440. // <selection activeCell="C2" sqref="C2"/>
  441. // </sheetView>
  442. // </sheetViews>
  443. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
  444. // <sheetData>
  445. // <row r="1" spans="1:2">
  446. // <c r="A1" t="s">
  447. // <v>0</v>
  448. // </c>
  449. // <c r="B1" t="s">
  450. // <v>1</v>
  451. // </c>
  452. // </row>
  453. // <row r="2" spans="1:2">
  454. // <c r="A2" t="s">
  455. // <v>2</v>
  456. // </c>
  457. // <c r="B2" t="s">
  458. // <v>3</v>
  459. // </c>
  460. // </row>
  461. // </sheetData>
  462. // <pageMargins left="0.7" right="0.7"
  463. // top="0.78740157499999996"
  464. // bottom="0.78740157499999996"
  465. // header="0.3"
  466. // footer="0.3"/>
  467. // </worksheet>`)
  468. // worksheet := new(xlsxWorksheet)
  469. // error := xml.NewDecoder(sheetxml).Decode(worksheet)
  470. // if error != nil {
  471. // t.Error(error.Error())
  472. // return
  473. // }
  474. // sst := new(xlsxSST)
  475. // error = xml.NewDecoder(sharedstringsXML).Decode(sst)
  476. // if error != nil {
  477. // t.Error(error.Error())
  478. // return
  479. // }
  480. // file := new(File)
  481. // file.referenceTable = MakeSharedStringRefTable(sst)
  482. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  483. // if maxRows != 2 {
  484. // t.Error("Expected maxRows == 2")
  485. // }
  486. // if maxCols != 2 {
  487. // t.Error("Expected maxCols == 2")
  488. // }
  489. // row := rows[0]
  490. // if len(row.Cells) != 2 {
  491. // t.Error("Expected len(row.Cells) == 2, got ", strconv.Itoa(len(row.Cells)))
  492. // }
  493. // cell1 := row.Cells[0]
  494. // if cell1.String() != "Foo" {
  495. // t.Error("Expected cell1.String() == 'Foo', got ", cell1.String())
  496. // }
  497. // cell2 := row.Cells[1]
  498. // if cell2.String() != "Bar" {
  499. // t.Error("Expected cell2.String() == 'Bar', got ", cell2.String())
  500. // }
  501. // }
  502. // func (l *LibSuite) TestReadRowsFromSheetWithLeadingEmptyRows(c *C) {
  503. // var sharedstringsXML = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  504. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2"><si><t>ABC</t></si><si><t>DEF</t></si></sst>`)
  505. // var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  506. // <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">
  507. // <dimension ref="A4:A5"/>
  508. // <sheetViews>
  509. // <sheetView tabSelected="1" workbookViewId="0">
  510. // <selection activeCell="A2" sqref="A2"/>
  511. // </sheetView>
  512. // </sheetViews>
  513. // <sheetFormatPr baseColWidth="10" defaultRowHeight="15" x14ac:dyDescent="0"/>
  514. // <sheetData>
  515. // <row r="4" spans="1:1">
  516. // <c r="A4" t="s">
  517. // <v>0</v>
  518. // </c>
  519. // </row>
  520. // <row r="5" spans="1:1">
  521. // <c r="A5" t="s">
  522. // <v>1</v>
  523. // </c>
  524. // </row>
  525. // </sheetData>
  526. // <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
  527. // <pageSetup paperSize="9" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
  528. // <extLst>
  529. // <ext uri="{64002731-A6B0-56B0-2670-7721B7C09600}" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main">
  530. // <mx:PLV Mode="0" OnePage="0" WScale="0"/>
  531. // </ext>
  532. // </extLst>
  533. // </worksheet>
  534. // `)
  535. // worksheet := new(xlsxWorksheet)
  536. // error := xml.NewDecoder(sheetxml).Decode(worksheet)
  537. // if error != nil {
  538. // t.Error(error.Error())
  539. // return
  540. // }
  541. // sst := new(xlsxSST)
  542. // error = xml.NewDecoder(sharedstringsXML).Decode(sst)
  543. // if error != nil {
  544. // t.Error(error.Error())
  545. // return
  546. // }
  547. // file := new(File)
  548. // file.referenceTable = MakeSharedStringRefTable(sst)
  549. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  550. // if maxRows != 2 {
  551. // t.Error("Expected maxRows == 2, got ", strconv.Itoa(len(rows)))
  552. // }
  553. // if maxCols != 1 {
  554. // t.Error("Expected maxCols == 1, got ", strconv.Itoa(maxCols))
  555. // }
  556. // }
  557. // func (l *LibSuite) TestReadRowsFromSheetWithEmptyCells(c *C) {
  558. // var sharedstringsXML = bytes.NewBufferString(`
  559. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  560. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="8" uniqueCount="5">
  561. // <si>
  562. // <t>Bob</t>
  563. // </si>
  564. // <si>
  565. // <t>Alice</t>
  566. // </si>
  567. // <si>
  568. // <t>Sue</t>
  569. // </si>
  570. // <si>
  571. // <t>Yes</t>
  572. // </si>
  573. // <si>
  574. // <t>No</t>
  575. // </si>
  576. // </sst>
  577. // `)
  578. // var sheetxml = bytes.NewBufferString(`
  579. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  580. // <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"/>
  581. // <sheetData>
  582. // <row r="1" spans="1:3">
  583. // <c r="A1" t="s">
  584. // <v>
  585. // 0
  586. // </v>
  587. // </c>
  588. // <c r="B1" t="s">
  589. // <v>
  590. // 1
  591. // </v>
  592. // </c>
  593. // <c r="C1" t="s">
  594. // <v>
  595. // 2
  596. // </v>
  597. // </c>
  598. // </row>
  599. // <row r="2" spans="1:3">
  600. // <c r="A2" t="s">
  601. // <v>
  602. // 3
  603. // </v>
  604. // </c>
  605. // <c r="B2" t="s">
  606. // <v>
  607. // 4
  608. // </v>
  609. // </c>
  610. // <c r="C2" t="s">
  611. // <v>
  612. // 3
  613. // </v>
  614. // </c>
  615. // </row>
  616. // <row r="3" spans="1:3">
  617. // <c r="A3" t="s">
  618. // <v>
  619. // 4
  620. // </v>
  621. // </c>
  622. // <c r="C3" t="s">
  623. // <v>
  624. // 3
  625. // </v>
  626. // </c>
  627. // </row>
  628. // </sheetData>
  629. // <pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/>
  630. // </worksheet>
  631. // `)
  632. // worksheet := new(xlsxWorksheet)
  633. // error := xml.NewDecoder(sheetxml).Decode(worksheet)
  634. // if error != nil {
  635. // t.Error(error.Error())
  636. // return
  637. // }
  638. // sst := new(xlsxSST)
  639. // error = xml.NewDecoder(sharedstringsXML).Decode(sst)
  640. // if error != nil {
  641. // t.Error(error.Error())
  642. // return
  643. // }
  644. // file := new(File)
  645. // file.referenceTable = MakeSharedStringRefTable(sst)
  646. // rows, maxCols, maxRows := readRowsFromSheet(worksheet, file)
  647. // if maxRows != 3 {
  648. // t.Error("Expected maxRows == 3, got ", strconv.Itoa(len(rows)))
  649. // }
  650. // if maxCols != 3 {
  651. // t.Error("Expected maxCols == 3, got ", strconv.Itoa(maxCols))
  652. // }
  653. // row := rows[2]
  654. // if len(row.Cells) != 3 {
  655. // t.Error("Expected len(row.Cells) == 3, got ", strconv.Itoa(len(row.Cells)))
  656. // }
  657. // cell1 := row.Cells[0]
  658. // if cell1.String() != "No" {
  659. // t.Error("Expected cell1.String() == 'No', got ", cell1.String())
  660. // }
  661. // cell2 := row.Cells[1]
  662. // if cell2.String() != "" {
  663. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  664. // }
  665. // cell3 := row.Cells[2]
  666. // if cell3.String() != "Yes" {
  667. // t.Error("Expected cell3.String() == 'Yes', got ", cell3.String())
  668. // }
  669. // }
  670. // func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
  671. // var row *Row
  672. // var cell1, cell2, cell3, cell4 *Cell
  673. // var sharedstringsXML = bytes.NewBufferString(`
  674. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  675. // <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>`)
  676. // var sheetxml = bytes.NewBufferString(`
  677. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  678. // <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>
  679. // `)
  680. // worksheet := new(xlsxWorksheet)
  681. // error := xml.NewDecoder(sheetxml).Decode(worksheet)
  682. // if error != nil {
  683. // t.Error(error.Error())
  684. // return
  685. // }
  686. // sst := new(xlsxSST)
  687. // error = xml.NewDecoder(sharedstringsXML).Decode(sst)
  688. // if error != nil {
  689. // t.Error(error.Error())
  690. // return
  691. // }
  692. // file := new(File)
  693. // file.referenceTable = MakeSharedStringRefTable(sst)
  694. // rows, maxCol, maxRow := readRowsFromSheet(worksheet, file)
  695. // if maxCol != 4 {
  696. // t.Error("Expected maxCol == 4, got ", strconv.Itoa(maxCol))
  697. // }
  698. // if maxRow != 8 {
  699. // t.Error("Expected maxRow == 8, got ", strconv.Itoa(maxRow))
  700. // }
  701. // row = rows[0]
  702. // if len(row.Cells) != 4 {
  703. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  704. // }
  705. // cell1 = row.Cells[0]
  706. // if cell1.String() != "A" {
  707. // t.Error("Expected cell1.String() == 'A', got ", cell1.String())
  708. // }
  709. // cell2 = row.Cells[1]
  710. // if cell2.String() != "B" {
  711. // t.Error("Expected cell2.String() == 'B', got ", cell2.String())
  712. // }
  713. // cell3 = row.Cells[2]
  714. // if cell3.String() != "C" {
  715. // t.Error("Expected cell3.String() == 'C', got ", cell3.String())
  716. // }
  717. // cell4 = row.Cells[3]
  718. // if cell4.String() != "D" {
  719. // t.Error("Expected cell4.String() == 'D', got ", cell4.String())
  720. // }
  721. // row = rows[1]
  722. // if len(row.Cells) != 4 {
  723. // t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))
  724. // }
  725. // cell1 = row.Cells[0]
  726. // if cell1.String() != "1" {
  727. // t.Error("Expected cell1.String() == '1', got ", cell1.String())
  728. // }
  729. // cell2 = row.Cells[1]
  730. // if cell2.String() != "" {
  731. // t.Error("Expected cell2.String() == '', got ", cell2.String())
  732. // }
  733. // cell3 = row.Cells[2]
  734. // if cell3.String() != "" {
  735. // t.Error("Expected cell3.String() == '', got ", cell3.String())
  736. // }
  737. // cell4 = row.Cells[3]
  738. // if cell4.String() != "" {
  739. // t.Error("Expected cell4.String() == '', got ", cell4.String())
  740. // }
  741. // }