1 Star 0 Fork 0

Erdian718 / xlsx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
record.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
Lite89 提交于 2023-07-13 18:02 . fix: fix Sheet.GetRecords bug
package xlsx
import (
"time"
"gitee.com/lite89/xlsx/internal"
)
// Record represents a record.
type Record struct {
dict map[string]int
cells []*internal.Cell
}
// String gets the record value as string.
func (a *Record) String(key string) string {
return a.cell(key).String()
}
// Bool gets the record value as bool.
func (a *Record) Bool(key string) bool {
return a.cell(key).Bool()
}
// Float gets the record value as float64.
func (a *Record) Float(key string) float64 {
return a.cell(key).Float()
}
// Int gets the record value as int.
func (a *Record) Int(key string) int {
return a.cell(key).Int()
}
// Time gets the record value as time.
func (a *Record) Time(key string) time.Time {
return a.cell(key).Time()
}
func (a *Record) cell(key string) *Cell {
if idx, ok := a.dict[key]; ok && idx < len(a.cells) {
return &Cell{a.cells[idx]}
}
return new(Cell)
}
// Records represents a records.
type Records struct {
dict map[string]int
rows []*internal.Row
index int
}
// Begin begins a iteration and returns the first record.
func (a *Records) Begin() *Record {
if a == nil {
return nil
}
a.index = 0
return a.Next()
}
// Next returns the next record.
func (a *Records) Next() *Record {
if a == nil {
return nil
}
if a.index < len(a.rows) {
record := &Record{dict: a.dict}
if row := a.rows[a.index]; row != nil {
record.cells = row.Cells
}
a.index++
return record
}
return nil
}
Go
1
https://gitee.com/erdian718/xlsx.git
git@gitee.com:erdian718/xlsx.git
erdian718
xlsx
xlsx
master

搜索帮助