lib_test.go 25 KB

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