diff --git a/col.go b/col.go index 8636566..010790e 100644 --- a/col.go +++ b/col.go @@ -51,6 +51,9 @@ type XfRk struct { func (xf *XfRk) String(wb *WorkBook) string { idx := int(xf.Index) if len(wb.Xfs) > idx { + if wb.Xfs[idx] == nil { + return xf.Rk.String() + } fNo := wb.Xfs[idx].formatNo() if fNo >= 164 { // user defined format if formatter := wb.Formats[fNo]; formatter != nil { @@ -168,9 +171,13 @@ type NumberCol struct { } func (c *NumberCol) String(wb *WorkBook) []string { - if fNo := wb.Xfs[c.Index].formatNo(); fNo != 0 { - t := timeFromExcelTime(c.Float, wb.dateMode == 1) - return []string{yymmdd.Format(t, wb.Formats[fNo].str)} + if int(c.Index) < len(wb.Xfs) && wb.Xfs[c.Index] != nil { + if fNo := wb.Xfs[c.Index].formatNo(); fNo != 0 { + t := timeFromExcelTime(c.Float, wb.dateMode == 1) + if fmtObj := wb.Formats[fNo]; fmtObj != nil { + return []string{yymmdd.Format(t, fmtObj.str)} + } + } } return []string{strconv.FormatFloat(c.Float, 'f', -1, 64)} } @@ -218,7 +225,10 @@ type LabelsstCol struct { } func (c *LabelsstCol) String(wb *WorkBook) []string { - return []string{wb.sst[int(c.Sst)]} + if int(c.Sst) < len(wb.sst) { + return []string{wb.sst[int(c.Sst)]} + } + return []string{""} } type labelCol struct { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b1b4a60 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/extrame/xls + +go 1.20 + +require ( + github.com/extrame/goyymmdd v0.0.0-20210114090516-7cc815f00d1a + golang.org/x/text v0.30.0 +)