File: compatibility_test.go

package info (click to toggle)
golang-github-tealeg-xlsx 1.0.3+git20181024.dbf71b6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 19,088 kB
  • sloc: makefile: 2
file content (103 lines) | stat: -rw-r--r-- 2,695 bytes parent folder | download | duplicates (2)
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
package xlsx

import (
	"os"

	. "gopkg.in/check.v1"
)

type GoogleDocsExcelSuite struct{}

var _ = Suite(&GoogleDocsExcelSuite{})

// Test that we can successfully read an XLSX file generated by
// Google Docs.
func (g *GoogleDocsExcelSuite) TestGoogleDocsExcel(c *C) {
	wd_path, _ := os.Getwd()
	xlsxFile, err := OpenFile(wd_path + "/../../../../../testdocs/googleDocsTest.xlsx")
	c.Assert(err, IsNil)
	c.Assert(xlsxFile, NotNil)
}

type MacExcelSuite struct{}

var _ = Suite(&MacExcelSuite{})

// 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 (m *MacExcelSuite) TestMacExcel(c *C) {
	wd_path, _ := os.Getwd()
	xlsxFile, err := OpenFile(wd_path + "/../../../../../testdocs/macExcelTest.xlsx")
	c.Assert(err, IsNil)
	c.Assert(xlsxFile, NotNil)
	if val, err := xlsxFile.Sheet["普通技能"].Cell(0, 0).FormattedValue(); err != nil {
		c.Error(err)
	} else {
		c.Assert(val, Equals, "编号")
	}
}

type MacNumbersSuite struct{}

var _ = Suite(&MacNumbersSuite{})

// Test that we can successfully read an XLSX file generated by
// Numbers for Mac.
func (m *MacNumbersSuite) TestMacNumbers(c *C) {
	wd_path, _ := os.Getwd()
	xlsxFile, err := OpenFile(wd_path + "/../../../../../testdocs/macNumbersTest.xlsx")
	c.Assert(err, IsNil)
	c.Assert(xlsxFile, NotNil)
	sheet, ok := xlsxFile.Sheet["主动技能"]
	c.Assert(ok, Equals, true)
	if val, err := sheet.Cell(0, 0).FormattedValue(); err != nil {
		c.Error(err)
	} else {
		c.Assert(val, Equals, "编号")
	}
}

type WpsBlankLineSuite struct{}

var _ = Suite(&WorksheetSuite{})

// 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 (w *WpsBlankLineSuite) TestWpsBlankLine(c *C) {
	wd_path, _ := os.Getwd()
	xlsxFile, err := OpenFile(wd_path + "/../../../../../testdocs/wpsBlankLineTest.xlsx")
	c.Assert(err, IsNil)
	c.Assert(xlsxFile, NotNil)
	sheet := xlsxFile.Sheet["Sheet1"]
	row := sheet.Rows[0]
	cell := row.Cells[0]

	expected := "编号"
	var val string

	if val, err = cell.FormattedValue(); err != nil {
		c.Error(err)
	}
	c.Assert(val, Equals, expected)

	row = sheet.Rows[2]
	cell = row.Cells[0]
	if val, err = cell.FormattedValue(); err != nil {
		c.Error(err)
	}
	c.Assert(val, Equals, expected)

	row = sheet.Rows[4]
	cell = row.Cells[1]
	if val, err = cell.FormattedValue(); err != nil {
		c.Error(err)
	}
	c.Assert(val, Equals, "")

	if val, err = sheet.Rows[4].Cells[2].FormattedValue(); err != nil {
		c.Error(err)
	}
	c.Assert(val, Equals, expected)
}