-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworksheet.go
50 lines (44 loc) · 1.05 KB
/
worksheet.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
package goexcelerate
import "fmt"
type Worksheet struct {
Name string
Cells map[int]map[int]any
ParentWb *Workbook
ShowGridLines bool
Panes *Panes
}
func (ws *Worksheet) SetCellValue(x int, y int, value any) {
if x <= 0 && y <= 0 {
panic("x and y should be >=1")
}
if ws.Cells == nil {
ws.Cells = make(map[int]map[int]any)
}
if ws.Cells[x] == nil {
ws.Cells[x] = make(map[int]any)
}
ws.Cells[x][y] = value
}
func (ws Worksheet) GetXMLData() <-chan string {
//rows := []string{}
channel := make(chan string)
go func(){
defer close(channel)
for row, cols := range ws.Cells {
GetRowString(row, cols, channel)
}
}()
return channel
}
func GetRowString(row int, cols map[int]any, ch chan<-string) {
row_ := fmt.Sprintf(`<row r="%d"> `, row)
for col, val := range cols {
row_ = row_ + GetColString(row, col, val)
}
row_ = row_ + "</row>"
ch <- row_
}
func GetColString(row int, col int, val any) string {
column := fmt.Sprintf(`<c r="%s%d"> <v>%v</v> </c>`, COORD_TO_COLUMN[col], row, val)
return column
}