lib_test.go 25 KB

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