lib_test.go 25 KB

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