excel

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExcelTagKey = "excel"
	Pattern     = "name:(.*?);|index:(.*?);|width:(.*?);|needMerge:(.*?);|replace:(.*?);"
)

Variables

This section is empty.

Functions

func DownLoadExcel

func DownLoadExcel(fileName string, res http.ResponseWriter, file *excelize.File)

DownLoadExcel 下载

func ExportExcel

func ExportExcel(sheet, title, fields string, isGhbj, isIgnore bool, list interface{}, changeHead map[string]string, e *Excel) (err error)

ExportExcel excel导出

func GetExcelColumnName

func GetExcelColumnName(columnNumber int) string

GetExcelColumnName 根据列数生成 Excel 列名

func ImportBySheet

func ImportBySheet(f *excelize.File, dst interface{}, sheetName string, headIndex, startRow int) (err error)

ImportBySheet 导入数据(读取指定sheet)sheetName Sheet名称

func ImportExcel

func ImportExcel(f *excelize.File, dst interface{}, headIndex, startRow int) (err error)

ImportExcel 导入数据(单个sheet) 需要在传入的结构体中的字段加上tag:excel:"title:列头名称;" f 获取到的excel对象、dst 导入目标对象【传指针】 headIndex 表头的索引,从0开始(用于获取表头名字) startRow 头行行数(从第startRow+1行开始扫)

func IsContain

func IsContain(items interface{}, item interface{}) bool

IsContain 判断数组中是否包含指定元素

func NormalDownLoad

func NormalDownLoad(fileName, sheet, title string, isGhbj bool, list interface{}, res http.ResponseWriter) error

NormalDownLoad 导出excel并下载(单个sheet)

func NormalDynamicDownLoad

func NormalDynamicDownLoad(fileName, sheet, title, fields string, isGhbj, isIgnore bool,
	list interface{}, changeHead map[string]string, res http.ResponseWriter) error

NormalDynamicDownLoad 动态导出excel并下载(单个sheet) isIgnore 是否忽略指定字段(true 要忽略的字段 false 要导出的字段) fields 选择的字段,多个字段用逗号隔开,最后一个字段后面也要加逗号,如:字段1,字段2,字段3, changeHead 要改变表头的字段,格式是{"字段1":"更改的表头1","字段2":"更改的表头2"}

func NormalDynamicExport

func NormalDynamicExport(list interface{}, sheet, title, fields string, isGhbj, isIgnore bool, changeHead map[string]string) (file *excelize.File, err error)

NormalDynamicExport 导出excel ** 需要在传入的结构体中的字段加上tag:excelize:"title:列头名称;index:列下标(从0开始);" list 需要导出的对象数组、sheet sheet名称、title 标题、isGhbj 是否设置隔行背景色

Types

type Excel

type Excel struct {
	F             *excelize.File // excel 对象
	TitleStyle    int            // 表头样式
	HeadStyle     int            // 表头样式
	ContentStyle1 int            // 主体样式1,无背景色
	ContentStyle2 int            // 主体样式2,有背景色
}

func ExcelInit

func ExcelInit() (e *Excel)

ExcelInit 初始化

type ExcelTag

type ExcelTag struct {
	Value     interface{}
	Name      string // 表头标题
	Index     int    // 列下标(从0开始)
	Width     int    // 列宽
	NeedMerge bool   // 是否需要合并
	Replace   string // 替换(需要替换的内容_替换后的内容。比如:1_未开始 ==> 表示1替换为未开始)
}

func NewExcelTag

func NewExcelTag() ExcelTag

NewExcelTag 构造函数,返回一个带有默认值的 ExcelTag 实例

func (*ExcelTag) GetTag

func (e *ExcelTag) GetTag(tag string) (err error)

GetTag 读取字段tag值

Jump to

Keyboard shortcuts

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