spreadsheet: default new cells to numeric with implicit zero value

This commit is contained in:
Todd 2017-09-14 17:16:19 -05:00
parent 1ff1b074f7
commit 111567b74e
2 changed files with 7 additions and 1 deletions

View File

@ -53,6 +53,7 @@ func (c Cell) clearValue() {
c.x.F = nil
c.x.Is = nil
c.x.V = nil
c.x.TAttr = sml.ST_CellTypeUnset
}
// SetInlineString adds a string inline instead of in the shared strings table.
@ -113,7 +114,8 @@ func (c Cell) GetValueAsNumber() (float64, error) {
return math.NaN(), errors.New("cell is not of number type")
}
if c.x.V == nil {
return math.NaN(), errors.New("cell has no value")
// empty cells have an implicit zero value
return 0, nil
}
return strconv.ParseFloat(*c.x.V, 64)
}

View File

@ -62,6 +62,8 @@ func (r Row) SetHidden(hidden bool) {
// AddCell adds a cell to a spreadsheet.
func (r Row) AddCell() Cell {
c := spreadsheetml.NewCT_Cell()
c.TAttr = spreadsheetml.ST_CellTypeN
r.x.C = append(r.x.C, c)
nextIdx := uint32(0)
for _, c := range r.x.C {
@ -92,6 +94,8 @@ func (r Row) Cells() []Cell {
// invaild spreadsheet.
func (r Row) AddNamedCell(col string) Cell {
c := spreadsheetml.NewCT_Cell()
c.TAttr = spreadsheetml.ST_CellTypeN
r.x.C = append(r.x.C, c)
c.RAttr = gooxml.Stringf("%s%d", col, r.RowNumber())
return Cell{r.w, r.s, r.x, c}