Skip to content

Commit

Permalink
Merge pull request #63 from simon3z/master
Browse files Browse the repository at this point in the history
Add Date Format support to NumberCol
  • Loading branch information
extrame authored Apr 26, 2020
2 parents 5397868 + b8b06ac commit 60fcb0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions col.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"time"

"github.com/extrame/goyymmdd"
yymmdd "github.com/extrame/goyymmdd"
)

//content type
Expand Down Expand Up @@ -54,16 +54,15 @@ func (xf *XfRk) String(wb *WorkBook) string {
fNo := wb.Xfs[idx].formatNo()
if fNo >= 164 { // user defined format
if formatter := wb.Formats[fNo]; formatter != nil {
if (strings.Contains(formatter.str, "#") || strings.Contains(formatter.str, ".00")){
if strings.Contains(formatter.str, "#") || strings.Contains(formatter.str, ".00") {
//If format contains # or .00 then this is a number
return xf.Rk.String()
}else{
return xf.Rk.String()
} else {
i, f, isFloat := xf.Rk.number()
if !isFloat {
f = float64(i)
}
t := timeFromExcelTime(f, wb.dateMode == 1)

return yymmdd.Format(t, formatter.str)
}
}
Expand Down Expand Up @@ -162,6 +161,10 @@ 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)}
}
return []string{strconv.FormatFloat(c.Float, 'f', -1, 64)}
}

Expand Down
7 changes: 4 additions & 3 deletions workbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"unicode/utf16"

"golang.org/x/text/encoding/charmap"
)

Expand Down Expand Up @@ -162,9 +163,9 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
return
}
func decodeWindows1251(enc []byte) string {
dec := charmap.Windows1251.NewDecoder()
out, _ := dec.Bytes(enc)
return string(out)
dec := charmap.Windows1251.NewDecoder()
out, _ := dec.Bytes(enc)
return string(out)
}
func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err error) {
if w.Is5ver {
Expand Down

0 comments on commit 60fcb0b

Please sign in to comment.