excel

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSheetByCell added in v1.1.0

func AddSheetByCell(f *XlsxFile, data [][]Cell, sheetName string) error

func Decode

func Decode(r io.Reader) ([][][]string, error)

return []sheet{[]row{[]cell}} cell 的值即使为空,也可通过下标访问,不会出现越界问题

func Export added in v1.1.0

func Export(w io.Writer, data [][]Cell, sheetName string) error

func ExportExcel

func ExportExcel(w io.Writer, data [][]string, sheetName string) error

ExportExcel 导出 excel 参数w: 返回http.ResponseWriter 参数sheetName: 生成表单的名字 data数据内容为: data[row][col],由 title+content组成 例子: 第一行: ["name", "age", "city"]

第二行: ["excel", "15", "hangzhou"]

注:每一行和每一列需要完全对应,根据 row 和 col 导出 xlsx 格式的 excel

func ExportExcelByCell

func ExportExcelByCell(w io.Writer, data [][]Cell, sheetName string) error

ExportExcelByCell 支持 cell 粒度配置,可以实现单元格合并,样式调整等

func FirstNonempty

func FirstNonempty(rows [][]string) int

func IsEmpty

func IsEmpty(row []string) bool

func WriteFile added in v1.1.0

func WriteFile(w io.Writer, f *XlsxFile, filename string) error

Types

type Cell

type Cell struct {
	// 单元格的值
	Value string
	// 水平合并其他几个单元格
	// 以 A0 为例,默认为 0 表示不合并其他单元格,1 表示合并 A0,B1 两个单元格,2 表示合并 A0,B1,C2 三个单元格
	HorizontalMergeNum int
	// 垂直合并其他几个单元格
	// 以 A0 为例,默认为 0 表示不合并其他单元格,1 表示合并 A0,A2 两个单元格,2 表示合并 A0,A1,A2 三个单元格
	VerticalMergeNum int
}

Cell 单元格

A  B  C

1 A1 B1 C1 1 A2 B2 C2 1 A3 B3 C3

func EmptyCell

func EmptyCell() Cell

func EmptyCells

func EmptyCells(count int) []Cell

func NewCell

func NewCell(value string) Cell

func NewHMergeCell

func NewHMergeCell(value string, hMergeNum int) Cell

NewHMergeCell 需要配合 hMergeNum 个 EmptyCell 使用

func NewVMergeCell

func NewVMergeCell(value string, vMergeNum int) Cell

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Seeker
}

type WorkBook

type WorkBook interface {
	Rows(sheetName string) [][]string
}

func NewWorkBook

func NewWorkBook(f File, ext string, size int64) (WorkBook, error)

type XlsxFile added in v1.1.0

type XlsxFile struct {
	// contains filtered or unexported fields
}

func NewXLSXFile added in v1.1.0

func NewXLSXFile() *XlsxFile

Jump to

Keyboard shortcuts

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