Working file write and read

This commit is contained in:
sloum 2021-03-15 16:58:41 -07:00
parent 63eb0df708
commit aa0a6928c1
4 changed files with 42 additions and 17 deletions

View File

@ -58,27 +58,34 @@ func LoadFile(path string) {
os.Exit(1)
}
wb = makeWorkbook(path)
sheets := strings.Split(f[3:len(f)-1], string(Sheet))
wb.sheets = make([]sheet, 0, 2)
sheets := strings.Split(f[4:len(f)-1], fmt.Sprintf("%c", Sheet))
for _, sh := range sheets {
rows := strings.Split(sh, string(Row))
if len(sh) == 0 {
continue
}
rows := strings.Split(sh, fmt.Sprintf("%c", Row))
if len(rows) < 1 {
return
}
s := makeSheet("")
for i, row := range rows {
fields := strings.Split(row, string(Field))
if i == 0 {
s.name = fields[0]
s.cols, _ = strconv.Atoi(fields[1])
s.rows, _ = strconv.Atoi(fields[2])
s.zoom, _ = strconv.Atoi(fields[3])
continue
}
s.cells = append(s.cells, make([]cell, 0, s.cols))
for _, field := range fields {
sfields := strings.Split(rows[0], fmt.Sprintf("%c", Field))
s.name = sfields[0]
s.cols, _ = strconv.Atoi(sfields[1])
s.rows, _ = strconv.Atoi(sfields[2])
s.zoom, _ = strconv.Atoi(sfields[3])
s.cells = make([][]cell, s.rows)
for i, row := range rows[1:] {
fields := strings.Split(row, fmt.Sprintf("%c", Field))
s.cells[i] = make([]cell, s.cols)
for x, field := range fields {
c := cell{}
c.Update(field)
s.cells[i-1] = append(s.cells[i-1], c)
s.cells[i][x] = c
}
}
s.Recalculate()
// s.Recalculate()
wb.sheets = append(wb.sheets, s)
}
}

20
main.go
View File

@ -30,7 +30,17 @@ type point struct {
}
func runCommand(elems []string) {
if len(elems) == 0 {
return
}
switch elems[0] {
case "save":
if len(elems) >= 2 {
WriteFile(strings.Join(elems[1:], " "))
} else {
WriteFile(wb.path)
}
}
}
func Getch() rune {
@ -109,6 +119,12 @@ func IsFunc(val string) bool {
}
func main() {
wb = makeWorkbook("test.qsh")
args := os.Args
if len(args) > 1 {
LoadFile(args[1])
wb.sheets[wb.sheet].Recalculate()
} else {
wb = makeWorkbook("blank.tss")
}
wb.Run()
}

View File

@ -74,6 +74,7 @@ func (s sheet) CurrentValue(raw bool) string {
}
func (s *sheet) Recalculate() {
fmt.Println(s.cells)
for row, _ := range s.cells {
for col, _ := range s.cells[row] {
// TODO do this concurrently

1
test.qsh Normal file
View File

@ -0,0 +1 @@
tssSheet12362325A1 A2 +"Total"