excel

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSheetByCell

func AddSheetByCell(f *File, data [][]Cell, sheetName string, handlers ...SheetHandler) error

AddSheetByCell add sheet by cell data. You can add multiple sheets by calling this method multiple times.

func Decode

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

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

func DefaultCellStyle

func DefaultCellStyle() *xlsx.Style

func DefaultTitleCellStyle

func DefaultTitleCellStyle() *xlsx.Style

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 WriteFile

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

Types

type Cell

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

	// 单元格的样式
	Style *CellStyle
}

Cell 单元格

- A B C 1 A1 B1 C1 2 A2 B2 C2 3 A3 B3 C3

func ConvertStringSliceToCellSlice

func ConvertStringSliceToCellSlice(data []string) []Cell

func EmptyCell

func EmptyCell() Cell

func EmptyCells

func EmptyCells(count int) []Cell

func NewCell

func NewCell(value string, opts ...CellOption) Cell

func NewHMergeCell

func NewHMergeCell(value string, hMergeNum int) Cell

NewHMergeCell 需要在当前行配合 hMergeNum 个 EmptyCell 使用

func NewHMergeCellsAuto

func NewHMergeCellsAuto(value string, hMergeNum int) []Cell

func NewTitleCell

func NewTitleCell(value string, opts ...CellOption) Cell

func NewVMergeCell

func NewVMergeCell(value string, vMergeNum int) Cell

NewVMergeCell 需要在下方连续 vMergeNum 行配合 EmptyCell 使用;如果下方使用带 Value 的 Cell 也会被 VMergeCell 覆盖,无法展示

type CellOption

type CellOption func(*Cell)

func WithIsTitle

func WithIsTitle(isTitle bool) CellOption

func WithMergeNum

func WithMergeNum(h, v int) CellOption

func WithStyle

func WithStyle(s *xlsx.Style) CellOption

func WithTitleStyle

func WithTitleStyle(s *xlsx.Style) CellOption

type CellStyle

type CellStyle struct {
	IsTitle        bool
	OverwriteStyle *xlsx.Style
}

type Column

type Column []Cell

type DecodedFile

type DecodedFile struct {
	File   *File
	Sheets Sheets
}

func DecodeToSheets

func DecodeToSheets(r io.Reader) (*DecodedFile, error)

DecodeToSheets decode Excel file to Sheets. So you can get sheet by sheetName.

type File

type File struct {
	XlsxFile *xlsx.File

	UnmergedSlice [][][]string
}

func NewFile

func NewFile() *File

type Row

type Row []Cell

type Rows

type Rows []Row

type Sheet

type Sheet struct {
	XlsxSheet *xlsx.Sheet
	RefFile   *DecodedFile

	UnmergedSlice [][]string
}

func NewSheet

func NewSheet(sheet *xlsx.Sheet, df *DecodedFile) *Sheet

type SheetHandler

type SheetHandler func(sheet *xlsx.Sheet) error

func NewSheetHandlerForAutoColWidth

func NewSheetHandlerForAutoColWidth(totalColumNum int) SheetHandler

func NewSheetHandlerForDropList

func NewSheetHandlerForDropList(startRow, startCol, endRow, endCol int, dropList []string) SheetHandler

func NewSheetHandlerForTip

func NewSheetHandlerForTip(startRow, startCol, endRow, endCol int, title, msg string) SheetHandler

type Sheets

type Sheets struct {
	L []*Sheet
	M map[string]*Sheet
}

func EmptySheets

func EmptySheets() Sheets

Jump to

Keyboard shortcuts

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