excel

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

用于 vue.ant 前台表格生成 excel 文件的 支持定制表头表尾 即将成为共用模块

excel @since 0.0.11 模板生成

Index

Constants

View Source
const (
	A = iota + 65
	B
	C
	D
	E
	F
	G
	H
	I
	J
	K
	L
	M
	N
	O
	P
	Q
	R
	S
	T
	U
	V
	W
	X
	Y
	Z
)

Variables

This section is empty.

Functions

func APIPostExportExcel

func APIPostExportExcel(c *gin.Context)

func CenterStyle

func CenterStyle(f *excelize.File) int

CenterStyle 居中的样式 TODO 改成文件级别的全局 @since 0.0.11

func ColDataToInterface

func ColDataToInterface(c interface{}) interface{}

func FormColumnsToInterface

func FormColumnsToInterface(formColumns []table.Column) []interface{}

将表单中的列字段转换成 excel 可以写入的格式

func FormDataWriteExcel

func FormDataWriteExcel(file *excelize.File, columns []table.Column, nowRow int, data interface{}) (error, int)

从form 表单中的data字段读取数据 并写入 excel

func GetValueFromMapStringInterface

func GetValueFromMapStringInterface(i interface{}, key string) (interface{}, error)

GetValueFromMapStringInterface

func GetValueFromMapStringInterfaceToString added in v0.0.25

func GetValueFromMapStringInterfaceToString(i interface{}, key string) (string, error)

func MakeTitle

func MakeTitle(file *excelize.File, title string, columns []interface{}) error

MakeTitle 设置标题相关

func MergeCell

func MergeCell(f *excelize.File, sheet string, begin Axis, end Axis) error

MergeCell 合并单元格 @since 0.0.11

func NewFile

func NewFile(orientation bool) (*excelize.File, error)

NewFile 创建文件句柄 @since 0.0.11

func Register

func Register()

func RowsDataToInterface

func RowsDataToInterface(d interface{}) []interface{}

把各种奇怪的类型如 sql.NullString int64 float64等 转换为 interface{]

func Save

func Save(f *excelize.File, name string) error
Save 保存文件

@since 0.0.11

func SetColWidth

func SetColWidth(f *excelize.File, sheet string, axis Axis, width float64) error

SetColsWidth 设置字段的宽度 单个单元格 @since 0.0.11

func SetColsWidth

func SetColsWidth(f *excelize.File, sheet string, begin Axis, end Axis, width float64) error

SetColsWidth 设置字段的宽度 连读单元格首尾设置 @since 0.0.11 @since 0.0.23 不传宽度默认是15.5

func SetExcelHeader

func SetExcelHeader(file *excelize.File, sheet string, data []Cell, nowRow int) (error, int)

func SetFreeCell

func SetFreeCell(file *excelize.File, sheet string, header []Cell, nowRow int) (int, error)

任意写值 在一定区段内

func SetRowCallsValue

func SetRowCallsValue(f *excelize.File, sheet string, begin Axis, values []interface{}) error

SetRowCallsValue 横向依次写值 @since 0.0.11

func SetTitle

func SetTitle(f *excelize.File, sheet string, begin Axis, end Axis, value string) error

SetTitle 设置大标题 涉及到合并单元格和添加边框操作 @since 0.0.11

Types

type APIPostExportForm added in v0.0.25

type APIPostExportForm struct {
	Title       string         `json:"title" binding:"required"`
	Header      []Cell         `json:"header"`
	Columns     []table.Column `json:"columns" binding:"required"`
	Footer      []Cell         `json:"footer"`
	Data        interface{}    `json:"data"`
	Orientation bool           `json:"orientation"` // @since 0.0.23 false 为纵向 true 为横向
	Width       float64        `json:"width"`       // 0 为 15.5
}

APIPostExportForm 提取成通用表单

type Axis

type Axis struct {
	Row    int `json:"row"`
	Column int `json:"column"`
}

Axis 表示单元格 Row 行 数字 Column excel.A - excel.Z 使用 ToString / ColumnToString 即可快捷转换 @since 0.0.11

func (Axis) ColumnToString

func (a Axis) ColumnToString() string

ColumnToString 正确转换列字母 @since 0.0.11

func (Axis) ToString

func (a Axis) ToString() string

ToString 将结构体转换为 "A1" 的字符串 @since 0.0.11

type Cell

type Cell struct {
	Axis
	Value interface{} `json:"value"`
}

Jump to

Keyboard shortcuts

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