-
Notifications
You must be signed in to change notification settings - Fork 820
/
compatibility_test.go
107 lines (95 loc) · 2.91 KB
/
compatibility_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package xlsx
import (
"testing"
qt "github.com/frankban/quicktest"
)
// Test that we can successfully read an XLSX file generated by
// Google Docs.
func TestGoogleDocsExcel(t *testing.T) {
c := qt.New(t)
csRunO(c, "OpenExcel", func(c *qt.C, option FileOption) {
xlsxFile, err := OpenFile("./testdocs/googleDocsTest.xlsx", option)
c.Assert(err, qt.IsNil)
c.Assert(xlsxFile, qt.Not(qt.IsNil))
})
}
// Test that we can successfully read an XLSX file generated by
// Microsoft Excel for Mac. In particular this requires that we
// respect the contents of workbook.xml.rels, which maps the sheet IDs
// to their internal file names.
func TestMacExcel(t *testing.T) {
c := qt.New(t)
csRunO(c, "OpenMacExcel", func(c *qt.C, option FileOption) {
xlsxFile, err := OpenFile("./testdocs/macExcelTest.xlsx", option)
c.Assert(err, qt.IsNil)
c.Assert(xlsxFile, qt.Not(qt.IsNil))
sheet, ok := xlsxFile.Sheet["普通技能"]
c.Assert(ok, qt.Equals, true)
defer sheet.Close()
cell, err := sheet.Cell(0, 0)
c.Assert(err, qt.Equals, nil)
if val, err := cell.FormattedValue(); err != nil {
c.Error(err)
} else {
c.Assert(val, qt.Equals, "编号")
}
})
}
// Test that we can successfully read an XLSX file generated by
// Numbers for Mac.
func TestMacNumbers(t *testing.T) {
c := qt.New(t)
csRunO(c, "OpenMacNumbers", func(c *qt.C, option FileOption) {
xlsxFile, err := OpenFile("./testdocs/macNumbersTest.xlsx", option)
c.Assert(err, qt.IsNil)
c.Assert(xlsxFile, qt.Not(qt.IsNil))
sheet, ok := xlsxFile.Sheet["主动技能"]
c.Assert(ok, qt.Equals, true)
defer sheet.Close()
cell, err := sheet.Cell(0, 0)
c.Assert(err, qt.Equals, nil)
if val, err := cell.FormattedValue(); err != nil {
c.Error(err)
} else {
c.Assert(val, qt.Equals, "编号")
}
})
}
// Test that we can successfully read an XLSX file generated by
// Wps on windows. you can download it freely from http://www.wps.cn/
func TestWpsBlankLine(t *testing.T) {
c := qt.New(t)
csRunO(c, "OpenWps", func(c *qt.C, option FileOption) {
xlsxFile, err := OpenFile("./testdocs/wpsBlankLineTest.xlsx", option)
c.Assert(err, qt.Equals, nil)
c.Assert(xlsxFile, qt.Not(qt.IsNil))
sheet := xlsxFile.Sheet["Sheet1"]
row, err := sheet.Row(0)
c.Assert(err, qt.Equals, nil)
cell := row.GetCell(0)
expected := "编号"
var val string
if val, err = cell.FormattedValue(); err != nil {
c.Error(err)
}
c.Assert(val, qt.Equals, expected)
row, err = sheet.Row(2)
c.Assert(err, qt.Equals, nil)
cell = row.GetCell(0)
if val, err = cell.FormattedValue(); err != nil {
c.Error(err)
}
c.Assert(val, qt.Equals, expected)
row, err = sheet.Row(4)
c.Assert(err, qt.Equals, nil)
cell = row.GetCell(1)
if val, err = cell.FormattedValue(); err != nil {
c.Error(err)
}
c.Assert(val, qt.Equals, "")
if val, err = row.GetCell(2).FormattedValue(); err != nil {
c.Error(err)
}
c.Assert(val, qt.Equals, expected)
})
}