1
0
mirror of https://github.com/pbnjay/grate.git synced 2024-12-13 13:58:27 +02:00

fix some XFs when applyNumberFormat not defined

This commit is contained in:
Jeremy Jay 2021-02-18 16:57:27 -05:00
parent b1639e1723
commit 167574603f
4 changed files with 33 additions and 14 deletions

View File

@ -29,13 +29,17 @@ func (x *Formatter) Mode1904(enabled bool) {
// Add a custom number format to the formatter.
func (x *Formatter) Add(fmtID uint16, formatCode string) error {
if x.customCodes == nil {
x.customCodes = make(map[uint16]FmtFunc)
}
if strings.ToLower(formatCode) == "general" {
x.customCodes[fmtID] = goFormatters[0]
return nil
}
_, ok := goFormatters[fmtID]
if ok {
return errors.New("grate/commonxl: cannot replace default number formats")
}
if x.customCodes == nil {
x.customCodes = make(map[uint16]FmtFunc)
}
_, ok2 := x.customCodes[fmtID]
if ok2 {

View File

@ -209,15 +209,22 @@ func (s *WorkSheet) parse() error {
case RecTypeBoolErr:
rowIndex := int(binary.LittleEndian.Uint16(r.Data[:2]))
colIndex := int(binary.LittleEndian.Uint16(r.Data[2:4]))
//ixfe := binary.LittleEndian.Uint16(r.Data[4:6])
ixfe := int(binary.LittleEndian.Uint16(r.Data[4:6]))
if r.Data[7] == 0 {
// Boolean value
bv := false
if r.Data[6] == 1 {
bv = true
}
// FIXME: load ixfe to support "yes"/"no" custom formats
s.placeValue(rowIndex, colIndex, bv)
var rval interface{} = bv
var fno uint16
if ixfe < len(s.b.xfs) {
fno = s.b.xfs[ixfe]
}
if fval, ok := s.b.nfmt.Apply(fno, bv); ok {
rval = fval
}
s.placeValue(rowIndex, colIndex, rval)
//log.Printf("bool/error spec: %d %d %+v", rowIndex, colIndex, bv)
} else {
// it's an error, load the label
@ -305,8 +312,15 @@ func (s *WorkSheet) parse() error {
if fdata[2] != 0 {
bv = true
}
// FIXME: apply the ixfe format
s.placeValue(int(formulaRow), int(formulaCol), bv)
var rval interface{} = bv
var fno uint16
if ixfe < len(s.b.xfs) {
fno = s.b.xfs[ixfe]
}
if fval, ok := s.b.nfmt.Apply(fno, bv); ok {
rval = fval
}
s.placeValue(int(formulaRow), int(formulaCol), rval)
case 2:
// error value
be, ok := berrLookup[fdata[2]]

View File

@ -93,6 +93,7 @@ func (s *Sheet) parseSheet() error {
if err == nil {
val = fval
}
val = numFormat(&s.d.fmt, fval)
//log.Println("CELL NUMBER", val, numFormat)
case SharedStringCellType:
//log.Println("CELL SHSTR", val, currentCellType, numFormat)

View File

@ -125,10 +125,10 @@ func (d *Document) parseStyles(dec *xml.Decoder) error {
ax := getAttrs(v.Attr, "numFmtId", "applyNumberFormat", "xfId")
if section == 1 {
// load base styles, but only save number format
if ax[1] != "1" {
baseNumFormats = append(baseNumFormats, ax[0])
} else {
if ax[1] == "0" {
baseNumFormats = append(baseNumFormats, "0")
} else {
baseNumFormats = append(baseNumFormats, ax[0])
}
} else if section == 2 {
// actual referencable cell styles
@ -140,11 +140,11 @@ func (d *Document) parseStyles(dec *xml.Decoder) error {
}
// 2) check if this XF overrides the base format
if ax[1] == "1" {
numFmtID = ax[0]
} else {
if ax[1] == "0" {
// remove the format (if it was inherited)
numFmtID = "0"
} else {
numFmtID = ax[0]
}
nfid, _ := strconv.ParseInt(numFmtID, 10, 16)