compatibility_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package xlsx
  2. import . "gopkg.in/check.v1"
  3. type GoogleDocsExcelSuite struct{}
  4. var _ = Suite(&GoogleDocsExcelSuite{})
  5. // Test that we can successfully read an XLSX file generated by
  6. // Google Docs.
  7. func (g *GoogleDocsExcelSuite) TestGoogleDocsExcel(c *C) {
  8. xlsxFile, err := OpenFile("./testdocs/googleDocsTest.xlsx")
  9. c.Assert(err, IsNil)
  10. c.Assert(xlsxFile, NotNil)
  11. }
  12. type MacExcelSuite struct{}
  13. var _ = Suite(&MacExcelSuite{})
  14. // Test that we can successfully read an XLSX file generated by
  15. // Microsoft Excel for Mac. In particular this requires that we
  16. // respect the contents of workbook.xml.rels, which maps the sheet IDs
  17. // to their internal file names.
  18. func (m *MacExcelSuite) TestMacExcel(c *C) {
  19. xlsxFile, err := OpenFile("./testdocs/macExcelTest.xlsx")
  20. c.Assert(err, IsNil)
  21. c.Assert(xlsxFile, NotNil)
  22. if val, err := xlsxFile.Sheet["普通技能"].Cell(0, 0).FormattedValue(); err != nil {
  23. c.Error(err)
  24. } else {
  25. c.Assert(val, Equals, "编号")
  26. }
  27. }
  28. type MacNumbersSuite struct{}
  29. var _ = Suite(&MacNumbersSuite{})
  30. // Test that we can successfully read an XLSX file generated by
  31. // Numbers for Mac.
  32. func (m *MacNumbersSuite) TestMacNumbers(c *C) {
  33. xlsxFile, err := OpenFile("./testdocs/macNumbersTest.xlsx")
  34. c.Assert(err, IsNil)
  35. c.Assert(xlsxFile, NotNil)
  36. sheet, ok := xlsxFile.Sheet["主动技能"]
  37. c.Assert(ok, Equals, true)
  38. if val, err := sheet.Cell(0, 0).FormattedValue(); err != nil {
  39. c.Error(err)
  40. } else {
  41. c.Assert(val, Equals, "编号")
  42. }
  43. }
  44. type WpsBlankLineSuite struct{}
  45. var _ = Suite(&WorksheetSuite{})
  46. // Test that we can successfully read an XLSX file generated by
  47. // Wps on windows. you can download it freely from http://www.wps.cn/
  48. func (w *WpsBlankLineSuite) TestWpsBlankLine(c *C) {
  49. xlsxFile, err := OpenFile("./testdocs/wpsBlankLineTest.xlsx")
  50. c.Assert(err, IsNil)
  51. c.Assert(xlsxFile, NotNil)
  52. sheet := xlsxFile.Sheet["Sheet1"]
  53. row := sheet.Rows[0]
  54. cell := row.Cells[0]
  55. expected := "编号"
  56. var val string
  57. if val, err = cell.FormattedValue(); err != nil {
  58. c.Error(err)
  59. }
  60. c.Assert(val, Equals, expected)
  61. row = sheet.Rows[2]
  62. cell = row.Cells[0]
  63. if val, err = cell.FormattedValue(); err != nil {
  64. c.Error(err)
  65. }
  66. c.Assert(val, Equals, expected)
  67. row = sheet.Rows[4]
  68. cell = row.Cells[1]
  69. if val, err = cell.FormattedValue(); err != nil {
  70. c.Error(err)
  71. }
  72. c.Assert(val, Equals, "")
  73. if val, err = sheet.Rows[4].Cells[2].FormattedValue(); err != nil {
  74. c.Error(err)
  75. }
  76. c.Assert(val, Equals, expected)
  77. }