partly support time cell

This commit is contained in:
Liu Ming
2015-03-25 14:47:26 +08:00
parent 7345247a91
commit dff67234df
7 changed files with 151 additions and 56 deletions

30
col.go
View File

@@ -41,6 +41,17 @@ type XfRk struct {
Rk RK
}
func (xf *XfRk) String(wb *WorkBook) string {
switch wb.Xfs[21].formatNo() {
case 27:
if f, e := xf.Rk.Float(); e == nil {
t := TimeFromExcelTime(f, true)
return t.Format("2006.01") //TODO it should be international
}
}
return fmt.Sprintf("%s", xf.Rk.String())
}
type RK uint32
func (rk RK) String() string {
@@ -58,6 +69,23 @@ func (rk RK) String() string {
}
}
var ErrIsInt = fmt.Errorf("is int")
func (rk RK) Float() (float64, error) {
multiplied := rk & 1
isInt := rk & 2
val := rk >> 2
if isInt == 0 {
f := math.Float64frombits(uint64(val) << 34)
if multiplied != 0 {
f = f / 100
}
return f, nil
} else {
return 0.0, ErrIsInt
}
}
type MulrkCol struct {
Col
Xfrks []XfRk
@@ -72,7 +100,7 @@ func (c *MulrkCol) String(wb *WorkBook) []string {
var res = make([]string, len(c.Xfrks))
for i := 0; i < len(c.Xfrks); i++ {
xfrk := c.Xfrks[i]
res[i] = xfrk.Rk.String()
res[i] = xfrk.String(wb)
}
return res
}