1 Star 0 Fork 0

Erdian718 / xlsx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cell.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
Lite89 提交于 2022-12-02 17:17 . perf: support nan and inf
package xlsx
import (
"math"
"strconv"
"time"
"gitee.com/lite89/xlsx/internal"
"gitee.com/lite89/xlsx/util"
)
// Cell represents a cell.
type Cell struct {
raw *internal.Cell
}
// Style gets the cell style.
func (a *Cell) Style() string {
return a.raw.GetStyle()
}
// String gets the cell value as string.
func (a *Cell) String() string {
return a.raw.GetValue()
}
// Bool gets the cell value as bool.
func (a *Cell) Bool() bool {
return util.ToBool(a.raw.GetValue())
}
// Float gets the cell value as float64.
func (a *Cell) Float() float64 {
return util.ToFloat(a.raw.GetValue())
}
// Int gets the cell value as int.
func (a *Cell) Int() int {
return util.ToInt(a.raw.GetValue())
}
// Time gets the cell value as time.
func (a *Cell) Time() time.Time {
return util.ToTime(a.raw.GetValue())
}
// SetStyle sets the cell style.
func (a *Cell) SetStyle(s string) {
a.raw.SetStyle(s)
}
// SetString sets the cell string value.
func (a *Cell) SetString(v string) {
a.raw.SetValue(internal.TypeString, v)
}
// SetBool sets the cell bool value.
func (a *Cell) SetBool(v bool) {
if v {
a.raw.SetValue(internal.TypeBool, "1")
} else {
a.raw.SetValue(internal.TypeBool, "0")
}
}
// SetFloat sets the cell float64 value.
func (a *Cell) SetFloat(v float64) {
if math.IsNaN(v) {
a.raw.SetValue(internal.TypeError, "#NUM!")
return
}
if v > math.MaxFloat64 {
v = math.MaxFloat64
} else if v < -math.MaxFloat64 {
v = -math.MaxFloat64
}
a.raw.SetValue(internal.TypeNumber, strconv.FormatFloat(v, 'g', -1, 64))
}
// SetInt sets the cell int value.
func (a *Cell) SetInt(v int) {
a.SetFloat(float64(v))
}
// SetTime sets the cell time value.
func (a *Cell) SetTime(v time.Time) {
a.SetFloat(util.TimeToFloat(v))
}
Go
1
https://gitee.com/erdian718/xlsx.git
git@gitee.com:erdian718/xlsx.git
erdian718
xlsx
xlsx
master

搜索帮助