excel

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetaDataRowCount = 4 // 最小的行数,小于这个行数的表可能无意义
View Source
var TypGlobalNameMatcher = regexp.MustCompile("global_.+$") // global
View Source
var TypI18nNameMatcher = regexp.MustCompile(`i18n_.+$`) // i18n表
View Source
var TypNormalNameMatcher = regexp.MustCompile("[a-z0-9]+_.+$") // 普通表

Functions

func GetBareFileName

func GetBareFileName(filename string) string

GetBareFileName 返回文件名,返回csv文件名; 规律: 1. 无下划线,2. 无中文字,3. 无扩展名,大小写未改变

func GetNormalConfClassName

func GetNormalConfClassName(filename string) string

GetNormalConfClassName 输入文件名普通配置文件的类名

func GetSnakeCaseFileName

func GetSnakeCaseFileName(filename string) string

GetSnakeCaseFileName 返回蛇形裸文件名

func IsAutoGenColumnName

func IsAutoGenColumnName(name string) bool

func IsExist

func IsExist(filepath string) bool

IsExist filepath 对应的文件是否存在

func RemoveDir

func RemoveDir(p string) string

RemoveDir 去掉目录部分

func RemoveDirAndExt

func RemoveDirAndExt(fullPath string) string

RemoveDirAndExt 去掉目录部分,去掉扩展名部分

func RemoveEmptyCol

func RemoveEmptyCol(grid [][]string) [][]string

RemoveEmptyCol 删除空列

func RemoveExtension

func RemoveExtension(p string) string

RemoveExtension 去掉扩展名部分

func UpperFirstLetter

func UpperFirstLetter(name string) string

Types

type ColumnMeta

type ColumnMeta struct {
	Index int    // 列序号
	Name  string // 列名字 (对应sheet的第一行)
	Desc  string // 列描述(对应sheet的第二行)
	Typ   string // 列数据类型(对应sheet的第三行)
	Flag  string // 列 c/s 标记(对应sheet的第四行)
}

ColumnMeta column 的描述信息

func GenColumnMeta

func GenColumnMeta(grid [][]string) []ColumnMeta

GenColumnMeta 根据meta信息返回column对象

func NewColumnMeta

func NewColumnMeta(index int, name, desc, typ, flag string) ColumnMeta

type Excel

type Excel struct {
	FilePath string   // 文件名,表明读取的excel,带有路径和 ext后缀
	Size     int      // 文件大小 byte
	Sheets   []*Sheet // 表单
}

type ExcelHandler

type ExcelHandler struct {
}

ExcelHandler 负责处理读取,输出等对接外部的操作

func NewExcelHandler

func NewExcelHandler() ExcelHandler

func (ExcelHandler) ExportToCsv

func (h ExcelHandler) ExportToCsv(dir string, excel *Excel)

ExportToCsv 输出csv文件

func (ExcelHandler) ReadOne

func (h ExcelHandler) ReadOne(fullPath string) (*Excel, error)

ReadOne 读取一个文件

type Sheet

type Sheet struct {
	Index          int        // sheet序号
	Name           string     // sheet名字
	OriginalMaxRow int        // 原始sheet穿过来的max行数
	OriginalMaxCol int        // 原始sheet穿过来的max列数
	RowCount       int        // 数据的有效行数(不算metadata,排除掉文件的空行)
	ColCount       int        // 列数
	Grid           [][]string // 有效数据表格, grid[0] 表示第一个数据行,grid[0][1]: 表示第一个数据行的第二个格子的值
}

Sheet 对 sheet 的映射,用来存放数据

func NewSheet

func NewSheet(sheetIndex int, sheet *xlsx.Sheet) *Sheet

type Typ

type Typ int
const (
	TypInvalid Typ = iota // 占位
	TypGlobal             // 全局配置表
	TypNormal             // 普通配置表
	TypI18n               // 多语言配置表
)

配置表类型

func GetConfType

func GetConfType(filename string) (typ Typ)

GetConfType 获取配置文件的类型

func (Typ) String

func (t Typ) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL