file_test.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. package xlsx
  2. import (
  3. "encoding/xml"
  4. "path/filepath"
  5. . "gopkg.in/check.v1"
  6. )
  7. type FileSuite struct{}
  8. var _ = Suite(&FileSuite{})
  9. // Test we can correctly open a XSLX file and return a xlsx.File
  10. // struct.
  11. func (l *FileSuite) TestOpenFile(c *C) {
  12. var xlsxFile *File
  13. var error error
  14. xlsxFile, error = OpenFile("./testdocs/testfile.xlsx")
  15. c.Assert(error, IsNil)
  16. c.Assert(xlsxFile, NotNil)
  17. }
  18. func (l *FileSuite) TestOpenFileWithoutStyleAndSharedStrings(c *C) {
  19. var xlsxFile *File
  20. var error error
  21. xlsxFile, error = OpenFile("./testdocs/noStylesAndSharedStringsTest.xlsx")
  22. c.Assert(error, IsNil)
  23. c.Assert(xlsxFile, NotNil)
  24. }
  25. func (l *FileSuite) TestOpenFileWithChartsheet(c *C) {
  26. xlsxFile, error := OpenFile("./testdocs/testchartsheet.xlsx")
  27. c.Assert(error, IsNil)
  28. c.Assert(xlsxFile, NotNil)
  29. }
  30. // Test that we can correctly extract a reference table from the
  31. // sharedStrings.xml file embedded in the XLSX file and return a
  32. // reference table of string values from it.
  33. func (l *FileSuite) TestReadSharedStringsFromZipFile(c *C) {
  34. var xlsxFile *File
  35. var err error
  36. xlsxFile, err = OpenFile("./testdocs/testfile.xlsx")
  37. c.Assert(err, IsNil)
  38. c.Assert(xlsxFile.referenceTable, NotNil)
  39. }
  40. // Helper function used to test contents of a given xlsxXf against
  41. // expectations.
  42. func testXf(c *C, result, expected *xlsxXf) {
  43. c.Assert(result.ApplyAlignment, Equals, expected.ApplyAlignment)
  44. c.Assert(result.ApplyBorder, Equals, expected.ApplyBorder)
  45. c.Assert(result.ApplyFont, Equals, expected.ApplyFont)
  46. c.Assert(result.ApplyFill, Equals, expected.ApplyFill)
  47. c.Assert(result.ApplyProtection, Equals, expected.ApplyProtection)
  48. c.Assert(result.BorderId, Equals, expected.BorderId)
  49. c.Assert(result.FillId, Equals, expected.FillId)
  50. c.Assert(result.FontId, Equals, expected.FontId)
  51. c.Assert(result.NumFmtId, Equals, expected.NumFmtId)
  52. }
  53. // We can correctly extract a style table from the style.xml file
  54. // embedded in the XLSX file and return a styles struct from it.
  55. func (l *FileSuite) TestReadStylesFromZipFile(c *C) {
  56. var xlsxFile *File
  57. var err error
  58. var fontCount, fillCount, borderCount, cellStyleXfCount, cellXfCount int
  59. var font xlsxFont
  60. var fill xlsxFill
  61. var border xlsxBorder
  62. var xf xlsxXf
  63. xlsxFile, err = OpenFile("./testdocs/testfile.xlsx")
  64. c.Assert(err, IsNil)
  65. c.Assert(xlsxFile.styles, NotNil)
  66. fontCount = len(xlsxFile.styles.Fonts.Font)
  67. c.Assert(fontCount, Equals, 4)
  68. font = xlsxFile.styles.Fonts.Font[0]
  69. c.Assert(font.Sz.Val, Equals, "11")
  70. c.Assert(font.Name.Val, Equals, "Calibri")
  71. fillCount = xlsxFile.styles.Fills.Count
  72. c.Assert(fillCount, Equals, 3)
  73. fill = xlsxFile.styles.Fills.Fill[2]
  74. c.Assert(fill.PatternFill.PatternType, Equals, "solid")
  75. borderCount = xlsxFile.styles.Borders.Count
  76. c.Assert(borderCount, Equals, 2)
  77. border = xlsxFile.styles.Borders.Border[1]
  78. c.Assert(border.Left.Style, Equals, "thin")
  79. c.Assert(border.Right.Style, Equals, "thin")
  80. c.Assert(border.Top.Style, Equals, "thin")
  81. c.Assert(border.Bottom.Style, Equals, "thin")
  82. cellStyleXfCount = xlsxFile.styles.CellStyleXfs.Count
  83. c.Assert(cellStyleXfCount, Equals, 20)
  84. xf = xlsxFile.styles.CellStyleXfs.Xf[0]
  85. expectedXf := &xlsxXf{
  86. ApplyAlignment: true,
  87. ApplyBorder: true,
  88. ApplyFont: true,
  89. ApplyFill: false,
  90. ApplyProtection: true,
  91. BorderId: 0,
  92. FillId: 0,
  93. FontId: 0,
  94. NumFmtId: 164}
  95. testXf(c, &xf, expectedXf)
  96. c.Assert(xf.Alignment, NotNil)
  97. c.Assert(xf.Alignment.Horizontal, Equals, "general")
  98. c.Assert(xf.Alignment.Indent, Equals, 0)
  99. c.Assert(xf.Alignment.ShrinkToFit, Equals, false)
  100. c.Assert(xf.Alignment.TextRotation, Equals, 0)
  101. c.Assert(xf.Alignment.Vertical, Equals, "bottom")
  102. c.Assert(xf.Alignment.WrapText, Equals, false)
  103. cellXfCount = xlsxFile.styles.CellXfs.Count
  104. c.Assert(cellXfCount, Equals, 3)
  105. xf = xlsxFile.styles.CellXfs.Xf[0]
  106. expectedXf = &xlsxXf{
  107. ApplyAlignment: false,
  108. ApplyBorder: false,
  109. ApplyFont: false,
  110. ApplyFill: false,
  111. ApplyProtection: false,
  112. BorderId: 0,
  113. FillId: 0,
  114. FontId: 0,
  115. NumFmtId: 164}
  116. testXf(c, &xf, expectedXf)
  117. }
  118. // We can correctly extract a map of relationship Ids to the worksheet files in
  119. // which they are contained from the XLSX file.
  120. func (l *FileSuite) TestReadWorkbookRelationsFromZipFile(c *C) {
  121. var xlsxFile *File
  122. var err error
  123. xlsxFile, err = OpenFile("./testdocs/testfile.xlsx")
  124. c.Assert(err, IsNil)
  125. c.Assert(len(xlsxFile.Sheets), Equals, 3)
  126. sheet, ok := xlsxFile.Sheet["Tabelle1"]
  127. c.Assert(ok, Equals, true)
  128. c.Assert(sheet, NotNil)
  129. }
  130. // Style information is correctly extracted from the zipped XLSX file.
  131. func (l *FileSuite) TestGetStyleFromZipFile(c *C) {
  132. var xlsxFile *File
  133. var err error
  134. var style *Style
  135. var val string
  136. xlsxFile, err = OpenFile("./testdocs/testfile.xlsx")
  137. c.Assert(err, IsNil)
  138. sheetCount := len(xlsxFile.Sheets)
  139. c.Assert(sheetCount, Equals, 3)
  140. tabelle1 := xlsxFile.Sheet["Tabelle1"]
  141. row0 := tabelle1.Rows[0]
  142. cellFoo := row0.Cells[0]
  143. style = cellFoo.GetStyle()
  144. if val, err = cellFoo.FormattedValue(); err != nil {
  145. c.Error(err)
  146. }
  147. c.Assert(val, Equals, "Foo")
  148. c.Assert(style.Fill.BgColor, Equals, "FF33CCCC")
  149. c.Assert(style.ApplyFill, Equals, false)
  150. c.Assert(style.ApplyFont, Equals, true)
  151. row1 := tabelle1.Rows[1]
  152. cellQuuk := row1.Cells[1]
  153. style = cellQuuk.GetStyle()
  154. if val, err = cellQuuk.FormattedValue(); err != nil {
  155. c.Error(err)
  156. }
  157. c.Assert(val, Equals, "Quuk")
  158. c.Assert(style.Border.Left, Equals, "thin")
  159. c.Assert(style.ApplyBorder, Equals, true)
  160. cellBar := row0.Cells[1]
  161. if val, err = cellBar.FormattedValue(); err != nil {
  162. c.Error(err)
  163. }
  164. c.Assert(val, Equals, "Bar")
  165. c.Assert(cellBar.GetStyle().Fill.BgColor, Equals, "")
  166. }
  167. // Test we can create a File object from scratch
  168. func (l *FileSuite) TestCreateFile(c *C) {
  169. var xlsxFile *File
  170. xlsxFile = NewFile()
  171. c.Assert(xlsxFile, NotNil)
  172. }
  173. // Test that when we open a real XLSX file we create xlsx.Sheet
  174. // objects for the sheets inside the file and that these sheets are
  175. // themselves correct.
  176. func (l *FileSuite) TestCreateSheet(c *C) {
  177. var xlsxFile *File
  178. var err error
  179. var sheet *Sheet
  180. var row *Row
  181. xlsxFile, err = OpenFile("./testdocs/testfile.xlsx")
  182. c.Assert(err, IsNil)
  183. c.Assert(xlsxFile, NotNil)
  184. sheetLen := len(xlsxFile.Sheets)
  185. c.Assert(sheetLen, Equals, 3)
  186. sheet = xlsxFile.Sheet["Tabelle1"]
  187. rowLen := len(sheet.Rows)
  188. c.Assert(rowLen, Equals, 2)
  189. row = sheet.Rows[0]
  190. c.Assert(len(row.Cells), Equals, 2)
  191. cell := row.Cells[0]
  192. if val, err := cell.FormattedValue(); err != nil {
  193. c.Error(err)
  194. } else {
  195. c.Assert(val, Equals, "Foo")
  196. }
  197. }
  198. // Test that we can add a sheet to a File
  199. func (l *FileSuite) TestAddSheet(c *C) {
  200. var f *File
  201. f = NewFile()
  202. sheet, err := f.AddSheet("MySheet")
  203. c.Assert(err, IsNil)
  204. c.Assert(sheet, NotNil)
  205. c.Assert(len(f.Sheets), Equals, 1)
  206. c.Assert(f.Sheet["MySheet"], Equals, sheet)
  207. }
  208. // Test that AddSheet returns an error if you try to add two sheets with the same name
  209. func (l *FileSuite) TestAddSheetWithDuplicateName(c *C) {
  210. f := NewFile()
  211. _, err := f.AddSheet("MySheet")
  212. c.Assert(err, IsNil)
  213. _, err = f.AddSheet("MySheet")
  214. c.Assert(err, ErrorMatches, "duplicate sheet name 'MySheet'.")
  215. }
  216. // Test that we can append a sheet to a File
  217. func (l *FileSuite) TestAppendSheet(c *C) {
  218. var f *File
  219. f = NewFile()
  220. s := Sheet{}
  221. sheet, err := f.AppendSheet(s, "MySheet")
  222. c.Assert(err, IsNil)
  223. c.Assert(sheet, NotNil)
  224. c.Assert(len(f.Sheets), Equals, 1)
  225. c.Assert(f.Sheet["MySheet"], Equals, sheet)
  226. }
  227. // Test that AppendSheet returns an error if you try to add two sheets with the same name
  228. func (l *FileSuite) TestAppendSheetWithDuplicateName(c *C) {
  229. f := NewFile()
  230. s := Sheet{}
  231. _, err := f.AppendSheet(s, "MySheet")
  232. c.Assert(err, IsNil)
  233. _, err = f.AppendSheet(s, "MySheet")
  234. c.Assert(err, ErrorMatches, "duplicate sheet name 'MySheet'.")
  235. }
  236. // Test that we can get the Nth sheet
  237. func (l *FileSuite) TestNthSheet(c *C) {
  238. var f *File
  239. f = NewFile()
  240. sheet, _ := f.AddSheet("MySheet")
  241. sheetByIndex := f.Sheets[0]
  242. sheetByName := f.Sheet["MySheet"]
  243. c.Assert(sheetByIndex, NotNil)
  244. c.Assert(sheetByIndex, Equals, sheet)
  245. c.Assert(sheetByIndex, Equals, sheetByName)
  246. }
  247. // Test that we can create a Workbook and marshal it to XML.
  248. func (l *FileSuite) TestMarshalWorkbook(c *C) {
  249. var f *File
  250. f = NewFile()
  251. f.AddSheet("MyFirstSheet")
  252. f.AddSheet("MySecondSheet")
  253. workbook := f.makeWorkbook()
  254. workbook.Sheets.Sheet[0] = xlsxSheet{
  255. Name: "MyFirstSheet",
  256. SheetId: "1",
  257. Id: "rId1",
  258. State: "visible"}
  259. workbook.Sheets.Sheet[1] = xlsxSheet{
  260. Name: "MySecondSheet",
  261. SheetId: "2",
  262. Id: "rId2",
  263. State: "visible"}
  264. expectedWorkbook := `<?xml version="1.0" encoding="UTF-8"?>
  265. <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="Go XLSX"></fileVersion><workbookPr showObjects="all" date1904="false"></workbookPr><workbookProtection></workbookProtection><bookViews><workbookView showHorizontalScroll="true" showVerticalScroll="true" showSheetTabs="true" tabRatio="204" windowHeight="8192" windowWidth="16384" xWindow="0" yWindow="0"></workbookView></bookViews><sheets><sheet name="MyFirstSheet" sheetId="1" r:id="rId1" state="visible"></sheet><sheet name="MySecondSheet" sheetId="2" r:id="rId2" state="visible"></sheet></sheets><definedNames></definedNames><calcPr iterateCount="100" refMode="A1" iterateDelta="0.001"></calcPr></workbook>`
  266. output, err := xml.Marshal(workbook)
  267. c.Assert(err, IsNil)
  268. outputStr := replaceRelationshipsNameSpace(string(output))
  269. stringOutput := xml.Header + outputStr
  270. c.Assert(stringOutput, Equals, expectedWorkbook)
  271. }
  272. // Test that we can marshall a File to a collection of xml files
  273. func (l *FileSuite) TestMarshalFile(c *C) {
  274. var f *File
  275. f = NewFile()
  276. sheet1, _ := f.AddSheet("MySheet")
  277. row1 := sheet1.AddRow()
  278. cell1 := row1.AddCell()
  279. cell1.SetString("A cell!")
  280. sheet2, _ := f.AddSheet("AnotherSheet")
  281. row2 := sheet2.AddRow()
  282. cell2 := row2.AddCell()
  283. cell2.SetString("A cell!")
  284. parts, err := f.MarshallParts()
  285. c.Assert(err, IsNil)
  286. c.Assert(len(parts), Equals, 11)
  287. // sheets
  288. expectedSheet1 := `<?xml version="1.0" encoding="UTF-8"?>
  289. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr filterMode="false"><pageSetUpPr fitToPage="false"></pageSetUpPr></sheetPr><dimension ref="A1"></dimension><sheetViews><sheetView windowProtection="false" showFormulas="false" showGridLines="true" showRowColHeaders="true" showZeros="true" rightToLeft="false" tabSelected="true" showOutlineSymbols="true" defaultGridColor="true" view="normal" topLeftCell="A1" colorId="64" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100" workbookViewId="0"><selection pane="topLeft" activeCell="A1" activeCellId="0" sqref="A1"></selection></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.85"></sheetFormatPr><cols><col collapsed="false" hidden="false" max="1" min="1" style="1" width="9.5"></col></cols><sheetData><row r="1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData><printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"></printOptions><pageMargins left="0.7875" right="0.7875" top="1.05277777777778" bottom="1.05277777777778" header="0.7875" footer="0.7875"></pageMargins><pageSetup paperSize="9" scale="100" firstPageNumber="1" fitToWidth="1" fitToHeight="1" pageOrder="downThenOver" orientation="portrait" usePrinterDefaults="false" blackAndWhite="false" draft="false" cellComments="none" useFirstPageNumber="true" horizontalDpi="300" verticalDpi="300" copies="1"></pageSetup><headerFooter differentFirst="false" differentOddEven="false"><oddHeader>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12&amp;A</oddHeader><oddFooter>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12Page &amp;P</oddFooter></headerFooter></worksheet>`
  290. c.Assert(parts["xl/worksheets/sheet1.xml"], Equals, expectedSheet1)
  291. expectedSheet2 := `<?xml version="1.0" encoding="UTF-8"?>
  292. <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr filterMode="false"><pageSetUpPr fitToPage="false"></pageSetUpPr></sheetPr><dimension ref="A1"></dimension><sheetViews><sheetView windowProtection="false" showFormulas="false" showGridLines="true" showRowColHeaders="true" showZeros="true" rightToLeft="false" tabSelected="false" showOutlineSymbols="true" defaultGridColor="true" view="normal" topLeftCell="A1" colorId="64" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100" workbookViewId="0"><selection pane="topLeft" activeCell="A1" activeCellId="0" sqref="A1"></selection></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.85"></sheetFormatPr><cols><col collapsed="false" hidden="false" max="1" min="1" style="1" width="9.5"></col></cols><sheetData><row r="1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData><printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"></printOptions><pageMargins left="0.7875" right="0.7875" top="1.05277777777778" bottom="1.05277777777778" header="0.7875" footer="0.7875"></pageMargins><pageSetup paperSize="9" scale="100" firstPageNumber="1" fitToWidth="1" fitToHeight="1" pageOrder="downThenOver" orientation="portrait" usePrinterDefaults="false" blackAndWhite="false" draft="false" cellComments="none" useFirstPageNumber="true" horizontalDpi="300" verticalDpi="300" copies="1"></pageSetup><headerFooter differentFirst="false" differentOddEven="false"><oddHeader>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12&amp;A</oddHeader><oddFooter>&amp;C&amp;&#34;Times New Roman,Regular&#34;&amp;12Page &amp;P</oddFooter></headerFooter></worksheet>`
  293. c.Assert(parts["xl/worksheets/sheet2.xml"], Equals, expectedSheet2)
  294. // .rels.xml
  295. expectedRels := `<?xml version="1.0" encoding="UTF-8"?>
  296. <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  297. <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
  298. <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
  299. <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
  300. </Relationships>`
  301. c.Assert(parts["_rels/.rels"], Equals, expectedRels)
  302. // app.xml
  303. expectedApp := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  304. <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
  305. <TotalTime>0</TotalTime>
  306. <Application>Go XLSX</Application>
  307. </Properties>`
  308. c.Assert(parts["docProps/app.xml"], Equals, expectedApp)
  309. // core.xml
  310. expectedCore := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  311. <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></cp:coreProperties>`
  312. c.Assert(parts["docProps/core.xml"], Equals, expectedCore)
  313. // theme1.xml
  314. expectedTheme := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  315. <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office-Design">
  316. <a:themeElements>
  317. <a:clrScheme name="Office">
  318. <a:dk1>
  319. <a:sysClr val="windowText" lastClr="000000"/>
  320. </a:dk1>
  321. <a:lt1>
  322. <a:sysClr val="window" lastClr="FFFFFF"/>
  323. </a:lt1>
  324. <a:dk2>
  325. <a:srgbClr val="1F497D"/>
  326. </a:dk2>
  327. <a:lt2>
  328. <a:srgbClr val="EEECE1"/>
  329. </a:lt2>
  330. <a:accent1>
  331. <a:srgbClr val="4F81BD"/>
  332. </a:accent1>
  333. <a:accent2>
  334. <a:srgbClr val="C0504D"/>
  335. </a:accent2>
  336. <a:accent3>
  337. <a:srgbClr val="9BBB59"/>
  338. </a:accent3>
  339. <a:accent4>
  340. <a:srgbClr val="8064A2"/>
  341. </a:accent4>
  342. <a:accent5>
  343. <a:srgbClr val="4BACC6"/>
  344. </a:accent5>
  345. <a:accent6>
  346. <a:srgbClr val="F79646"/>
  347. </a:accent6>
  348. <a:hlink>
  349. <a:srgbClr val="0000FF"/>
  350. </a:hlink>
  351. <a:folHlink>
  352. <a:srgbClr val="800080"/>
  353. </a:folHlink>
  354. </a:clrScheme>
  355. <a:fontScheme name="Office">
  356. <a:majorFont>
  357. <a:latin typeface="Cambria"/>
  358. <a:ea typeface=""/>
  359. <a:cs typeface=""/>
  360. <a:font script="Jpan" typeface="MS Pゴシック"/>
  361. <a:font script="Hang" typeface="맑은 고딕"/>
  362. <a:font script="Hans" typeface="宋体"/>
  363. <a:font script="Hant" typeface="新細明體"/>
  364. <a:font script="Arab" typeface="Times New Roman"/>
  365. <a:font script="Hebr" typeface="Times New Roman"/>
  366. <a:font script="Thai" typeface="Tahoma"/>
  367. <a:font script="Ethi" typeface="Nyala"/>
  368. <a:font script="Beng" typeface="Vrinda"/>
  369. <a:font script="Gujr" typeface="Shruti"/>
  370. <a:font script="Khmr" typeface="MoolBoran"/>
  371. <a:font script="Knda" typeface="Tunga"/>
  372. <a:font script="Guru" typeface="Raavi"/>
  373. <a:font script="Cans" typeface="Euphemia"/>
  374. <a:font script="Cher" typeface="Plantagenet Cherokee"/>
  375. <a:font script="Yiii" typeface="Microsoft Yi Baiti"/>
  376. <a:font script="Tibt" typeface="Microsoft Himalaya"/>
  377. <a:font script="Thaa" typeface="MV Boli"/>
  378. <a:font script="Deva" typeface="Mangal"/>
  379. <a:font script="Telu" typeface="Gautami"/>
  380. <a:font script="Taml" typeface="Latha"/>
  381. <a:font script="Syrc" typeface="Estrangelo Edessa"/>
  382. <a:font script="Orya" typeface="Kalinga"/>
  383. <a:font script="Mlym" typeface="Kartika"/>
  384. <a:font script="Laoo" typeface="DokChampa"/>
  385. <a:font script="Sinh" typeface="Iskoola Pota"/>
  386. <a:font script="Mong" typeface="Mongolian Baiti"/>
  387. <a:font script="Viet" typeface="Times New Roman"/>
  388. <a:font script="Uigh" typeface="Microsoft Uighur"/>
  389. <a:font script="Geor" typeface="Sylfaen"/>
  390. </a:majorFont>
  391. <a:minorFont>
  392. <a:latin typeface="Calibri"/>
  393. <a:ea typeface=""/>
  394. <a:cs typeface=""/>
  395. <a:font script="Jpan" typeface="MS Pゴシック"/>
  396. <a:font script="Hang" typeface="맑은 고딕"/>
  397. <a:font script="Hans" typeface="宋体"/>
  398. <a:font script="Hant" typeface="新細明體"/>
  399. <a:font script="Arab" typeface="Arial"/>
  400. <a:font script="Hebr" typeface="Arial"/>
  401. <a:font script="Thai" typeface="Tahoma"/>
  402. <a:font script="Ethi" typeface="Nyala"/>
  403. <a:font script="Beng" typeface="Vrinda"/>
  404. <a:font script="Gujr" typeface="Shruti"/>
  405. <a:font script="Khmr" typeface="DaunPenh"/>
  406. <a:font script="Knda" typeface="Tunga"/>
  407. <a:font script="Guru" typeface="Raavi"/>
  408. <a:font script="Cans" typeface="Euphemia"/>
  409. <a:font script="Cher" typeface="Plantagenet Cherokee"/>
  410. <a:font script="Yiii" typeface="Microsoft Yi Baiti"/>
  411. <a:font script="Tibt" typeface="Microsoft Himalaya"/>
  412. <a:font script="Thaa" typeface="MV Boli"/>
  413. <a:font script="Deva" typeface="Mangal"/>
  414. <a:font script="Telu" typeface="Gautami"/>
  415. <a:font script="Taml" typeface="Latha"/>
  416. <a:font script="Syrc" typeface="Estrangelo Edessa"/>
  417. <a:font script="Orya" typeface="Kalinga"/>
  418. <a:font script="Mlym" typeface="Kartika"/>
  419. <a:font script="Laoo" typeface="DokChampa"/>
  420. <a:font script="Sinh" typeface="Iskoola Pota"/>
  421. <a:font script="Mong" typeface="Mongolian Baiti"/>
  422. <a:font script="Viet" typeface="Arial"/>
  423. <a:font script="Uigh" typeface="Microsoft Uighur"/>
  424. <a:font script="Geor" typeface="Sylfaen"/>
  425. </a:minorFont>
  426. </a:fontScheme>
  427. <a:fmtScheme name="Office">
  428. <a:fillStyleLst>
  429. <a:solidFill>
  430. <a:schemeClr val="phClr"/>
  431. </a:solidFill>
  432. <a:gradFill rotWithShape="1">
  433. <a:gsLst>
  434. <a:gs pos="0">
  435. <a:schemeClr val="phClr">
  436. <a:tint val="50000"/>
  437. <a:satMod val="300000"/>
  438. </a:schemeClr>
  439. </a:gs>
  440. <a:gs pos="35000">
  441. <a:schemeClr val="phClr">
  442. <a:tint val="37000"/>
  443. <a:satMod val="300000"/>
  444. </a:schemeClr>
  445. </a:gs>
  446. <a:gs pos="100000">
  447. <a:schemeClr val="phClr">
  448. <a:tint val="15000"/>
  449. <a:satMod val="350000"/>
  450. </a:schemeClr>
  451. </a:gs>
  452. </a:gsLst>
  453. <a:lin ang="16200000" scaled="1"/>
  454. </a:gradFill>
  455. <a:gradFill rotWithShape="1">
  456. <a:gsLst>
  457. <a:gs pos="0">
  458. <a:schemeClr val="phClr">
  459. <a:tint val="100000"/>
  460. <a:shade val="100000"/>
  461. <a:satMod val="130000"/>
  462. </a:schemeClr>
  463. </a:gs>
  464. <a:gs pos="100000">
  465. <a:schemeClr val="phClr">
  466. <a:tint val="50000"/>
  467. <a:shade val="100000"/>
  468. <a:satMod val="350000"/>
  469. </a:schemeClr>
  470. </a:gs>
  471. </a:gsLst>
  472. <a:lin ang="16200000" scaled="0"/>
  473. </a:gradFill>
  474. </a:fillStyleLst>
  475. <a:lnStyleLst>
  476. <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">
  477. <a:solidFill>
  478. <a:schemeClr val="phClr">
  479. <a:shade val="95000"/>
  480. <a:satMod val="105000"/>
  481. </a:schemeClr>
  482. </a:solidFill>
  483. <a:prstDash val="solid"/>
  484. </a:ln>
  485. <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">
  486. <a:solidFill>
  487. <a:schemeClr val="phClr"/>
  488. </a:solidFill>
  489. <a:prstDash val="solid"/>
  490. </a:ln>
  491. <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">
  492. <a:solidFill>
  493. <a:schemeClr val="phClr"/>
  494. </a:solidFill>
  495. <a:prstDash val="solid"/>
  496. </a:ln>
  497. </a:lnStyleLst>
  498. <a:effectStyleLst>
  499. <a:effectStyle>
  500. <a:effectLst>
  501. <a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0">
  502. <a:srgbClr val="000000">
  503. <a:alpha val="38000"/>
  504. </a:srgbClr>
  505. </a:outerShdw>
  506. </a:effectLst>
  507. </a:effectStyle>
  508. <a:effectStyle>
  509. <a:effectLst>
  510. <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
  511. <a:srgbClr val="000000">
  512. <a:alpha val="35000"/>
  513. </a:srgbClr>
  514. </a:outerShdw>
  515. </a:effectLst>
  516. </a:effectStyle>
  517. <a:effectStyle>
  518. <a:effectLst>
  519. <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0">
  520. <a:srgbClr val="000000">
  521. <a:alpha val="35000"/>
  522. </a:srgbClr>
  523. </a:outerShdw>
  524. </a:effectLst>
  525. <a:scene3d>
  526. <a:camera prst="orthographicFront">
  527. <a:rot lat="0" lon="0" rev="0"/>
  528. </a:camera>
  529. <a:lightRig rig="threePt" dir="t">
  530. <a:rot lat="0" lon="0" rev="1200000"/>
  531. </a:lightRig>
  532. </a:scene3d>
  533. <a:sp3d>
  534. <a:bevelT w="63500" h="25400"/>
  535. </a:sp3d>
  536. </a:effectStyle>
  537. </a:effectStyleLst>
  538. <a:bgFillStyleLst>
  539. <a:solidFill>
  540. <a:schemeClr val="phClr"/>
  541. </a:solidFill>
  542. <a:gradFill rotWithShape="1">
  543. <a:gsLst>
  544. <a:gs pos="0">
  545. <a:schemeClr val="phClr">
  546. <a:tint val="40000"/>
  547. <a:satMod val="350000"/>
  548. </a:schemeClr>
  549. </a:gs>
  550. <a:gs pos="40000">
  551. <a:schemeClr val="phClr">
  552. <a:tint val="45000"/>
  553. <a:shade val="99000"/>
  554. <a:satMod val="350000"/>
  555. </a:schemeClr>
  556. </a:gs>
  557. <a:gs pos="100000">
  558. <a:schemeClr val="phClr">
  559. <a:shade val="20000"/>
  560. <a:satMod val="255000"/>
  561. </a:schemeClr>
  562. </a:gs>
  563. </a:gsLst>
  564. <a:path path="circle">
  565. <a:fillToRect l="50000" t="-80000" r="50000" b="180000"/>
  566. </a:path>
  567. </a:gradFill>
  568. <a:gradFill rotWithShape="1">
  569. <a:gsLst>
  570. <a:gs pos="0">
  571. <a:schemeClr val="phClr">
  572. <a:tint val="80000"/>
  573. <a:satMod val="300000"/>
  574. </a:schemeClr>
  575. </a:gs>
  576. <a:gs pos="100000">
  577. <a:schemeClr val="phClr">
  578. <a:shade val="30000"/>
  579. <a:satMod val="200000"/>
  580. </a:schemeClr>
  581. </a:gs>
  582. </a:gsLst>
  583. <a:path path="circle">
  584. <a:fillToRect l="50000" t="50000" r="50000" b="50000"/>
  585. </a:path>
  586. </a:gradFill>
  587. </a:bgFillStyleLst>
  588. </a:fmtScheme>
  589. </a:themeElements>
  590. <a:objectDefaults>
  591. <a:spDef>
  592. <a:spPr/>
  593. <a:bodyPr/>
  594. <a:lstStyle/>
  595. <a:style>
  596. <a:lnRef idx="1">
  597. <a:schemeClr val="accent1"/>
  598. </a:lnRef>
  599. <a:fillRef idx="3">
  600. <a:schemeClr val="accent1"/>
  601. </a:fillRef>
  602. <a:effectRef idx="2">
  603. <a:schemeClr val="accent1"/>
  604. </a:effectRef>
  605. <a:fontRef idx="minor">
  606. <a:schemeClr val="lt1"/>
  607. </a:fontRef>
  608. </a:style>
  609. </a:spDef>
  610. <a:lnDef>
  611. <a:spPr/>
  612. <a:bodyPr/>
  613. <a:lstStyle/>
  614. <a:style>
  615. <a:lnRef idx="2">
  616. <a:schemeClr val="accent1"/>
  617. </a:lnRef>
  618. <a:fillRef idx="0">
  619. <a:schemeClr val="accent1"/>
  620. </a:fillRef>
  621. <a:effectRef idx="1">
  622. <a:schemeClr val="accent1"/>
  623. </a:effectRef>
  624. <a:fontRef idx="minor">
  625. <a:schemeClr val="tx1"/>
  626. </a:fontRef>
  627. </a:style>
  628. </a:lnDef>
  629. </a:objectDefaults>
  630. <a:extraClrSchemeLst/>
  631. </a:theme>`
  632. c.Assert(parts["xl/theme/theme1.xml"], Equals, expectedTheme)
  633. // sharedStrings.xml
  634. expectedXLSXSST := `<?xml version="1.0" encoding="UTF-8"?>
  635. <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1"><si><t>A cell!</t></si></sst>`
  636. c.Assert(parts["xl/sharedStrings.xml"], Equals, expectedXLSXSST)
  637. // workbook.xml.rels
  638. expectedXLSXWorkbookRels := `<?xml version="1.0" encoding="UTF-8"?>
  639. <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"></Relationship><Relationship Id="rId2" Target="worksheets/sheet2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"></Relationship><Relationship Id="rId3" Target="sharedStrings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"></Relationship><Relationship Id="rId4" Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"></Relationship><Relationship Id="rId5" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"></Relationship></Relationships>`
  640. c.Assert(parts["xl/_rels/workbook.xml.rels"], Equals, expectedXLSXWorkbookRels)
  641. // workbook.xml
  642. // Note that the following XML snippet is just pasted in here to correspond to the hack
  643. // added in file.go to support Apple Numbers so the test passes.
  644. // `xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"`
  645. expectedWorkbook := `<?xml version="1.0" encoding="UTF-8"?>
  646. <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="Go XLSX"></fileVersion><workbookPr showObjects="all" date1904="false"></workbookPr><workbookProtection></workbookProtection><bookViews><workbookView showHorizontalScroll="true" showVerticalScroll="true" showSheetTabs="true" tabRatio="204" windowHeight="8192" windowWidth="16384" xWindow="0" yWindow="0"></workbookView></bookViews><sheets><sheet name="MySheet" sheetId="1" r:id="rId1" state="visible"></sheet><sheet name="AnotherSheet" sheetId="2" r:id="rId2" state="visible"></sheet></sheets><definedNames></definedNames><calcPr iterateCount="100" refMode="A1" iterateDelta="0.001"></calcPr></workbook>`
  647. c.Assert(parts["xl/workbook.xml"], Equals, expectedWorkbook)
  648. // [Content_Types].xml
  649. expectedContentTypes := `<?xml version="1.0" encoding="UTF-8"?>
  650. <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"></Override><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"></Override><Override PartName="/xl/_rels/workbook.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"></Override><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"></Override><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"></Override><Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"></Override><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Default><Default Extension="xml" ContentType="application/xml"></Default></Types>`
  651. c.Assert(parts["[Content_Types].xml"], Equals, expectedContentTypes)
  652. // styles.xml
  653. //
  654. // For now we only allow simple string data in the
  655. // spreadsheet. Style support will follow.
  656. expectedStyles := `<?xml version="1.0" encoding="UTF-8"?>
  657. <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="12"/><name val="Verdana"/><family val="0"/><charset val="0"/></font></fonts><fills count="2"><fill><patternFill patternType="none"><fgColor rgb="FFFFFFFF"/><bgColor rgb="00000000"/></patternFill></fill><fill><patternFill patternType="lightGray"/></fill></fills><borders count="1"><border><left style="none"></left><right style="none"></right><top style="none"></top><bottom style="none"></bottom></border></borders><cellXfs count="2"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf></cellXfs></styleSheet>`
  658. c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
  659. }
  660. // We can save a File as a valid XLSX file at a given path.
  661. func (l *FileSuite) TestSaveFile(c *C) {
  662. var tmpPath string = c.MkDir()
  663. var f *File
  664. f = NewFile()
  665. sheet1, _ := f.AddSheet("MySheet")
  666. row1 := sheet1.AddRow()
  667. cell1 := row1.AddCell()
  668. cell1.Value = "A cell!"
  669. sheet2, _ := f.AddSheet("AnotherSheet")
  670. row2 := sheet2.AddRow()
  671. cell2 := row2.AddCell()
  672. cell2.Value = "A cell!"
  673. xlsxPath := filepath.Join(tmpPath, "TestSaveFile.xlsx")
  674. err := f.Save(xlsxPath)
  675. c.Assert(err, IsNil)
  676. // Let's eat our own dog food
  677. xlsxFile, err := OpenFile(xlsxPath)
  678. c.Assert(err, IsNil)
  679. c.Assert(xlsxFile, NotNil)
  680. c.Assert(len(xlsxFile.Sheets), Equals, 2)
  681. sheet1, ok := xlsxFile.Sheet["MySheet"]
  682. c.Assert(ok, Equals, true)
  683. c.Assert(len(sheet1.Rows), Equals, 1)
  684. row1 = sheet1.Rows[0]
  685. c.Assert(len(row1.Cells), Equals, 1)
  686. cell1 = row1.Cells[0]
  687. c.Assert(cell1.Value, Equals, "A cell!")
  688. }
  689. type SliceReaderSuite struct{}
  690. var _ = Suite(&SliceReaderSuite{})
  691. func (s *SliceReaderSuite) TestFileToSlice(c *C) {
  692. output, err := FileToSlice("./testdocs/testfile.xlsx")
  693. c.Assert(err, IsNil)
  694. fileToSliceCheckOutput(c, output)
  695. }
  696. func (s *SliceReaderSuite) TestFileToSliceMissingCol(c *C) {
  697. // Test xlsx file with the A column removed
  698. _, err := FileToSlice("./testdocs/testFileToSlice.xlsx")
  699. c.Assert(err, IsNil)
  700. }
  701. func (s *SliceReaderSuite) TestFileObjToSlice(c *C) {
  702. f, err := OpenFile("./testdocs/testfile.xlsx")
  703. output, err := f.ToSlice()
  704. c.Assert(err, IsNil)
  705. fileToSliceCheckOutput(c, output)
  706. }
  707. func fileToSliceCheckOutput(c *C, output [][][]string) {
  708. c.Assert(len(output), Equals, 3)
  709. c.Assert(len(output[0]), Equals, 2)
  710. c.Assert(len(output[0][0]), Equals, 2)
  711. c.Assert(output[0][0][0], Equals, "Foo")
  712. c.Assert(output[0][0][1], Equals, "Bar")
  713. c.Assert(len(output[0][1]), Equals, 2)
  714. c.Assert(output[0][1][0], Equals, "Baz")
  715. c.Assert(output[0][1][1], Equals, "Quuk")
  716. c.Assert(len(output[1]), Equals, 0)
  717. c.Assert(len(output[2]), Equals, 0)
  718. }
  719. func (l *FileSuite) TestReadWorkbookWithTypes(c *C) {
  720. var xlsxFile *File
  721. var err error
  722. xlsxFile, err = OpenFile("./testdocs/testcelltypes.xlsx")
  723. c.Assert(err, IsNil)
  724. c.Assert(len(xlsxFile.Sheets), Equals, 1)
  725. sheet := xlsxFile.Sheet["Sheet1"]
  726. c.Assert(len(sheet.Rows), Equals, 8)
  727. c.Assert(len(sheet.Rows[0].Cells), Equals, 2)
  728. // string 1
  729. c.Assert(sheet.Rows[0].Cells[0].Type(), Equals, CellTypeString)
  730. if val, err := sheet.Rows[0].Cells[0].FormattedValue(); err != nil {
  731. c.Error(err)
  732. } else {
  733. c.Assert(val, Equals, "hello world")
  734. }
  735. // string 2
  736. c.Assert(sheet.Rows[1].Cells[0].Type(), Equals, CellTypeString)
  737. if val, err := sheet.Rows[1].Cells[0].FormattedValue(); err != nil {
  738. c.Error(err)
  739. } else {
  740. c.Assert(val, Equals, "日本語")
  741. }
  742. // integer
  743. c.Assert(sheet.Rows[2].Cells[0].Type(), Equals, CellTypeNumeric)
  744. intValue, _ := sheet.Rows[2].Cells[0].Int()
  745. c.Assert(intValue, Equals, 12345)
  746. // float
  747. c.Assert(sheet.Rows[3].Cells[0].Type(), Equals, CellTypeNumeric)
  748. floatValue, _ := sheet.Rows[3].Cells[0].Float()
  749. c.Assert(floatValue, Equals, 1.024)
  750. // Now it can't detect date
  751. c.Assert(sheet.Rows[4].Cells[0].Type(), Equals, CellTypeNumeric)
  752. intValue, _ = sheet.Rows[4].Cells[0].Int()
  753. c.Assert(intValue, Equals, 40543)
  754. // bool
  755. c.Assert(sheet.Rows[5].Cells[0].Type(), Equals, CellTypeBool)
  756. c.Assert(sheet.Rows[5].Cells[0].Bool(), Equals, true)
  757. // formula
  758. c.Assert(sheet.Rows[6].Cells[0].Type(), Equals, CellTypeFormula)
  759. c.Assert(sheet.Rows[6].Cells[0].Formula(), Equals, "10+20")
  760. c.Assert(sheet.Rows[6].Cells[0].Value, Equals, "30")
  761. // error
  762. c.Assert(sheet.Rows[7].Cells[0].Type(), Equals, CellTypeError)
  763. c.Assert(sheet.Rows[7].Cells[0].Formula(), Equals, "10/0")
  764. c.Assert(sheet.Rows[7].Cells[0].Value, Equals, "#DIV/0!")
  765. }
  766. func (s *SliceReaderSuite) TestFileWithEmptyRows(c *C) {
  767. f, err := OpenFile("./testdocs/empty_rows.xlsx")
  768. c.Assert(err, IsNil)
  769. sheet, ok := f.Sheet["EmptyRows"]
  770. c.Assert(ok, Equals, true)
  771. if val, err := sheet.Cell(0, 0).FormattedValue(); err != nil {
  772. c.Error(err)
  773. } else {
  774. c.Assert(val, Equals, "")
  775. }
  776. if val, err := sheet.Cell(2, 0).FormattedValue(); err != nil {
  777. c.Error(err)
  778. } else {
  779. c.Assert(val, Equals, "A3")
  780. }
  781. }
  782. func (s *SliceReaderSuite) TestFileWithEmptyCols(c *C) {
  783. f, err := OpenFile("./testdocs/empty_rows.xlsx")
  784. c.Assert(err, IsNil)
  785. sheet, ok := f.Sheet["EmptyCols"]
  786. c.Assert(ok, Equals, true)
  787. if val, err := sheet.Cell(0, 0).FormattedValue(); err != nil {
  788. c.Error(err)
  789. } else {
  790. c.Assert(val, Equals, "")
  791. }
  792. if val, err := sheet.Cell(0, 2).FormattedValue(); err != nil {
  793. c.Error(err)
  794. } else {
  795. c.Assert(val, Equals, "C1")
  796. }
  797. }