mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-29 13:49:10 +08:00
spreadsheet: default new cells to numeric with implicit zero value
This commit is contained in:
parent
1ff1b074f7
commit
111567b74e
@ -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)
|
||||
}
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user