1 Star 0 Fork 0

jackytse / tabtoy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sheet.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
黑色灵猫 提交于 2018-02-01 14:37 . 修复: 浮点数按原精度输出
package v2
import (
"github.com/tealeg/xlsx"
"strings"
)
// 描述一个表单
type Sheet struct {
*xlsx.Sheet
Row int // 当前行
Column int // 当前列
file *File // 指向父级
}
// 取行列信息
func (self *Sheet) GetRC() (int, int) {
return self.Row + 1, self.Column + 1
}
// 获取单元格 cursor=行, index=列
func (self *Sheet) GetCellData(cursor, index int) string {
if cursor >= len(self.Rows) {
return ""
}
r := self.Rows[cursor]
for len(r.Cells) <= index {
r.AddCell()
}
return strings.TrimSpace(r.Cells[index].Value)
}
func (self *Sheet) GetCellDataAsNumeric(cursor, index int) string {
if cursor >= len(self.Rows) {
return ""
}
r := self.Rows[cursor]
for len(r.Cells) <= index {
r.AddCell()
}
gn, err := r.Cells[index].GeneralNumeric()
if err != nil {
return ""
}
return gn
}
// 设置单元格
func (self *Sheet) SetCellData(cursor, index int, data string) {
self.Cell(cursor, index).Value = data
}
// 整行都是空的
func (self *Sheet) IsFullRowEmpty(row, maxCol int) bool {
for col := 0; col < maxCol; col++ {
data := self.GetCellData(row, col)
if data != "" {
return false
}
}
return true
}
func NewSheet(file *File, sheet *xlsx.Sheet) *Sheet {
self := &Sheet{
file: file,
Sheet: sheet,
}
return self
}
Go
1
https://gitee.com/jackytse/tabtoy.git
git@gitee.com:jackytse/tabtoy.git
jackytse
tabtoy
tabtoy
v0.1.0

搜索帮助