summaryrefslogtreecommitdiff
path: root/excelize_test.go
blob: 7d37a6a2783fe46bd7e0475f834e840179c61733 (plain) (blame)
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
package excelize

import (
	"strconv"
	"testing"
)

func TestExcelize(t *testing.T) {
	// Test update a XLSX file
	file, err := OpenFile("./test/Workbook1.xlsx")
	if err != nil {
		t.Log(err)
	}
	file.UpdateLinkedValue()
	file.SetCellInt("SHEET2", "A1", 100)
	file.SetCellStr("SHEET2", "C11", "Knowns")
	file.NewSheet(3, "TestSheet")
	file.SetCellInt("Sheet3", "A23", 10)
	file.SetCellStr("SHEET3", "b230", "10")
	file.SetCellStr("SHEET10", "b230", "10")
	file.SetActiveSheet(2)
	// Test read cell value with given illegal rows number
	file.GetCellValue("Sheet2", "a-1")
	// Test read cell value with given lowercase column number
	file.GetCellValue("Sheet2", "a5")
	file.GetCellValue("Sheet2", "C11")
	file.GetCellValue("Sheet2", "D11")
	file.GetCellValue("Sheet2", "D12")
	// Test read cell value with given axis large than exists row
	file.GetCellValue("Sheet2", "E13")

	for i := 1; i <= 300; i++ {
		file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
	}
	err = file.Save()
	if err != nil {
		t.Log(err)
	}
	// Test write file to given path
	err = file.WriteTo("./test/Workbook_2.xlsx")
	if err != nil {
		t.Log(err)
	}
	// Test write file to not exist directory
	err = file.WriteTo("")
	if err != nil {
		t.Log(err)
	}

	// Test create a XLSX file
	file2 := CreateFile()
	file2.NewSheet(2, "XLSXSheet2")
	file2.NewSheet(3, "XLSXSheet3")
	file2.SetCellInt("Sheet2", "A23", 56)
	file2.SetCellStr("SHEET1", "B20", "42")
	file2.SetActiveSheet(0)
	err = file2.WriteTo("./test/Workbook_3.xlsx")
	if err != nil {
		t.Log(err)
	}

	// Test open a XLSX file with given illegal path
	_, err = OpenFile("./test/Workbook.xlsx")
	if err != nil {
		t.Log(err)
	}
}