mirror of
https://github.com/pbnjay/grate.git
synced 2025-01-21 05:21:49 +02:00
deal with invalid files instead of making all files worse
This commit is contained in:
parent
460301037b
commit
10c14fa766
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pbnjay/grate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sheet holds raw and rendered values for a spreadsheet.
|
// Sheet holds raw and rendered values for a spreadsheet.
|
||||||
@ -19,10 +21,6 @@ type Sheet struct {
|
|||||||
// Resize the sheet for the number of rows and cols given.
|
// Resize the sheet for the number of rows and cols given.
|
||||||
// Newly added cells default to blank.
|
// Newly added cells default to blank.
|
||||||
func (s *Sheet) Resize(rows, cols int) {
|
func (s *Sheet) Resize(rows, cols int) {
|
||||||
// some sheets are off by one
|
|
||||||
rows++
|
|
||||||
cols++
|
|
||||||
|
|
||||||
if rows <= 0 {
|
if rows <= 0 {
|
||||||
rows = 1
|
rows = 1
|
||||||
}
|
}
|
||||||
@ -37,7 +35,7 @@ func (s *Sheet) Resize(rows, cols int) {
|
|||||||
s.Rows = append(s.Rows, make([]Cell, cols))
|
s.Rows = append(s.Rows, make([]Cell, cols))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; len(s.Rows[i]) < cols; i++ {
|
for i := 0; i < s.NumRows && len(s.Rows[i]) < cols; i++ {
|
||||||
r2 := make([]Cell, cols-len(s.Rows[i]))
|
r2 := make([]Cell, cols-len(s.Rows[i]))
|
||||||
s.Rows[i] = append(s.Rows[i], r2...)
|
s.Rows[i] = append(s.Rows[i], r2...)
|
||||||
}
|
}
|
||||||
@ -45,10 +43,22 @@ func (s *Sheet) Resize(rows, cols int) {
|
|||||||
|
|
||||||
// Put the value at the cell location given.
|
// Put the value at the cell location given.
|
||||||
func (s *Sheet) Put(row, col int, value interface{}, fmtNum uint16) {
|
func (s *Sheet) Put(row, col int, value interface{}, fmtNum uint16) {
|
||||||
|
log.Println(row, col, value, fmtNum)
|
||||||
if row >= s.NumRows || col >= s.NumCols {
|
if row >= s.NumRows || col >= s.NumCols {
|
||||||
|
if grate.Debug {
|
||||||
log.Printf("grate: cell out of bounds row %d>=%d, col %d>=%d",
|
log.Printf("grate: cell out of bounds row %d>=%d, col %d>=%d",
|
||||||
row, s.NumRows, col, s.NumCols)
|
row, s.NumRows, col, s.NumCols)
|
||||||
return
|
}
|
||||||
|
|
||||||
|
// per the spec, this is an invalid Excel file
|
||||||
|
// but we'll resize in place instead of crashing out
|
||||||
|
if row >= s.NumRows {
|
||||||
|
s.NumRows = row + 1
|
||||||
|
}
|
||||||
|
if col >= s.NumCols {
|
||||||
|
s.NumCols = col + 1
|
||||||
|
}
|
||||||
|
s.Resize(s.NumRows, s.NumCols)
|
||||||
}
|
}
|
||||||
|
|
||||||
ct, ok := s.Formatter.getCellType(fmtNum)
|
ct, ok := s.Formatter.getCellType(fmtNum)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user