-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage_test.go
128 lines (104 loc) · 2.41 KB
/
usage_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package xlsx
import (
"fmt"
"testing"
"time"
)
func Test_Usage(t *testing.T) {
workbook := NewWorkbook("./spreadsheet-1.xlsx")
worksheet := workbook.AddWorksheet(&WorksheetOptions{
Name: "Data",
})
for i := 0; i < 3; i++ {
row, _ := worksheet.AddRow()
cell, _ := row.AddCell()
cell.Value = "test 1"
cell, _ = row.AddCell()
cell.Value = 2
cell, _ = row.AddCell()
cell.Value = time.Now()
cell, _ = row.AddCell()
cell.Value = "test 4"
cell, _ = row.AddCell()
cell.Value = "test 5"
cell, _ = row.AddCell()
cell.Value = "test 6"
cell, _ = row.AddCell()
cell.Value = "test 7"
cell, _ = row.AddCell()
cell.Value = "test 8"
cell, _ = row.AddCell()
cell.Value = "test 9"
cell, _ = row.AddCell()
cell.Value = "test 10"
err := worksheet.CommitRows()
if i%50000 == 0 {
fmt.Println(i)
}
if err != nil {
t.Errorf("failed to commit rows: %v", err)
return
}
}
err := worksheet.Commit()
if err != nil {
t.Errorf("failed to commit worksheet: %v", err)
return
}
err = workbook.Commit()
if err != nil {
t.Errorf("failed to commit workbook: %v", err)
}
fmt.Println("workbook.tempRootDir", workbook.tempRootDir)
}
func Test_Usage_AddCellWithKey(t *testing.T) {
workbook := NewWorkbook("./spreadsheet-2.xlsx")
worksheet := workbook.AddWorksheet(&WorksheetOptions{
Name: "Data",
})
worksheet.DefineColumns([]*WorksheetColumn{
&WorksheetColumn{Key: "sup1", Value: "sup 1"},
&WorksheetColumn{Key: "sup2", Value: "sup 2"},
&WorksheetColumn{Key: "sup3", Value: "sup 3"},
})
for i := 0; i < 3; i++ {
row, _ := worksheet.AddRow()
cell, err := row.AddCellWithKey("sup1")
if err != nil {
t.Errorf("failed to add cell: %v", err)
}
cell.Value = "test 1"
if i%2 == 0 {
cell, err = row.AddCellWithKey("sup2")
if err != nil {
t.Errorf("failed to add cell: %v", err)
return
}
cell.Value = 2
}
cell, err = row.AddCellWithKey("sup3")
if err != nil {
t.Errorf("failed to add cell: %v", err)
return
}
cell.Value = time.Now()
err = worksheet.CommitRows()
if err != nil {
t.Errorf("failed to commit rows: %v", err)
return
}
if i%50000 == 0 {
fmt.Println(i)
}
}
err := worksheet.Commit()
if err != nil {
t.Errorf("failed to commit worksheet: %v", err)
return
}
err = workbook.Commit()
if err != nil {
t.Errorf("failed to commit workbook: %v", err)
}
fmt.Println("workbook.tempRootDir", workbook.tempRootDir)
}