From 179b5b454d04ffa6ae86b100128f71a403eee816 Mon Sep 17 00:00:00 2001 From: Pismak Ivan Date: Thu, 29 Aug 2024 19:18:54 +0300 Subject: [PATCH 1/3] support additional date-time formats --- xls/record/format.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xls/record/format.go b/xls/record/format.go index fe1ad8f..86f2414 100644 --- a/xls/record/format.go +++ b/xls/record/format.go @@ -10,6 +10,12 @@ import ( "strings" ) +const ( + DefaultDateFormat = "DD/MM/YYYY" + DefaultTimeFormat = "hh:mm" + DefaultTimeFormatWithSeconds = "hh:mm:ss" +) + //FORMAT: Number Format var FormatRecord = []byte{0x1E, 0x04} //(41Eh) @@ -107,8 +113,14 @@ func (r *Format) GetFormatString(data structure.CellData) string { return fmt.Sprintf("%.f", data.GetFloat64()) } else { t := helpers.TimeFromExcelTime(data.GetFloat64(), false) - dateFormat := strings.ReplaceAll(r.String(), "HH:MM:SS", "hh:mm:ss") - dateFormat = strings.ReplaceAll(dateFormat, "\\", "") + dateStringReplacer := strings.NewReplacer( + "dd/MM/yyyy", DefaultDateFormat, + "HH:MM:SS", DefaultTimeFormatWithSeconds, + "HH:mm", DefaultTimeFormat, + "\\", "", + ) + dateFormat := dateStringReplacer.Replace(r.String()) + return fmtdate.Format(dateFormat, t) } From b482ca60feb12a676ce260ca9322a9fa37f06f70 Mon Sep 17 00:00:00 2001 From: Pismak Ivan Date: Thu, 29 Aug 2024 19:23:11 +0300 Subject: [PATCH 2/3] support additional date-time formats --- xls/record/format.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xls/record/format.go b/xls/record/format.go index 86f2414..bbd2384 100644 --- a/xls/record/format.go +++ b/xls/record/format.go @@ -115,8 +115,8 @@ func (r *Format) GetFormatString(data structure.CellData) string { t := helpers.TimeFromExcelTime(data.GetFloat64(), false) dateStringReplacer := strings.NewReplacer( "dd/MM/yyyy", DefaultDateFormat, - "HH:MM:SS", DefaultTimeFormatWithSeconds, "HH:mm", DefaultTimeFormat, + "HH:MM:SS", DefaultTimeFormatWithSeconds, "\\", "", ) dateFormat := dateStringReplacer.Replace(r.String()) From f64888ffa1caccb99af56768b3b6e67e1b5d4de3 Mon Sep 17 00:00:00 2001 From: Pismak Ivan Date: Fri, 20 Dec 2024 20:18:30 +0300 Subject: [PATCH 3/3] skip incorrect potentially corrupted string index --- xls/record/labelSst.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xls/record/labelSst.go b/xls/record/labelSst.go index dd468a3..2ff0830 100644 --- a/xls/record/labelSst.go +++ b/xls/record/labelSst.go @@ -40,7 +40,13 @@ func (r *LabelSSt) GetCol() [2]byte { } func (r *LabelSSt) GetString() string { - return r.sst.Rgb[helpers.BytesToUint32(r.isst[:])].String() + number := helpers.BytesToUint32(r.isst[:]) + + if int(number) < len(r.sst.Rgb) { + return r.sst.Rgb[number].String() + } + + return "" } func (r *LabelSSt) GetFloat64() (fl float64) { @@ -58,9 +64,6 @@ func (r *LabelSSt) GetXFIndex() int { return int(helpers.BytesToUint16(r.ixfe[:])) } - - - func (r *LabelSSt) Read(stream []byte, sst *SST) { r.sst = sst copy(r.rw[:], stream[:2])