Documentation
¶
Index ¶
- func AddSheetByCell(f *File, data [][]Cell, sheetName string, handlers ...SheetHandler) error
- func Decode(r io.Reader) ([][][]string, error)
- func DefaultCellStyle() *xlsx.Style
- func DefaultTitleCellStyle() *xlsx.Style
- func ExportExcel(w io.Writer, data [][]string, sheetName string) error
- func ExportExcelByCell(w io.Writer, data [][]Cell, sheetName string) error
- func WriteFile(w io.Writer, f *File, filename string) error
- type Cell
- func ConvertStringSliceToCellSlice(data []string) []Cell
- func EmptyCell() Cell
- func EmptyCells(count int) []Cell
- func NewCell(value string, opts ...CellOption) Cell
- func NewHMergeCell(value string, hMergeNum int) Cell
- func NewHMergeCellsAuto(value string, hMergeNum int) []Cell
- func NewTitleCell(value string, opts ...CellOption) Cell
- func NewVMergeCell(value string, vMergeNum int) Cell
- type CellOption
- type CellStyle
- type Column
- type DecodedFile
- type File
- type Row
- type Rows
- type Sheet
- type SheetHandler
- type Sheets
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 ¶
Decode excel file to [][][]string return []sheet{[]row{[]cell}} cell 的值即使为空,也可通过下标访问,不会出现越界问题
func DefaultCellStyle ¶
func DefaultTitleCellStyle ¶
func ExportExcel ¶
ExportExcel 导出 excel 参数w: 返回http.ResponseWriter 参数sheetName: 生成表单的名字 data数据内容为: data[row][col],由 title+content组成 例子: 第一行: ["name", "age", "city"]
第二行: ["excel", "15", "hangzhou"]
注:每一行和每一列需要完全对应,根据 row 和 col 导出 xlsx 格式的 excel
func ExportExcelByCell ¶
ExportExcelByCell 支持 cell 粒度配置,可以实现单元格合并,样式调整等
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 EmptyCells ¶
func NewCell ¶
func NewCell(value string, opts ...CellOption) Cell
func NewHMergeCell ¶
NewHMergeCell 需要在当前行配合 hMergeNum 个 EmptyCell 使用
func NewHMergeCellsAuto ¶
func NewTitleCell ¶
func NewTitleCell(value string, opts ...CellOption) Cell
func NewVMergeCell ¶
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 DecodedFile ¶
func DecodeToSheets ¶
func DecodeToSheets(r io.Reader) (*DecodedFile, error)
DecodeToSheets decode Excel file to Sheets. So you can get sheet by sheetName.
type Sheet ¶
type Sheet struct {
XlsxSheet *xlsx.Sheet
RefFile *DecodedFile
UnmergedSlice [][]string
}
type SheetHandler ¶
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