excel

package
v1.53.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package excel 提供基于模板的 Excel 导入导出:泛型列表导出/导入, 依赖用户预调好的 .xlsx 模板文件(样式/格式/公式),数据区域按行填充。 映射规则:struct tag `excel:"列名"` 匹配模板表头;无 tag 时用字段名匹配。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export[T any](tpl Template, data []T, writer io.Writer) error

Export 将泛型数据列表按模板填充到 writer(返回 .xlsx 字节流)。 模板的数据区域从 DataStartRow 开始,每行对应 data 的一项,列序按模板表头匹配。

func ExportToFile

func ExportToFile[T any](tpl Template, data []T, outputPath string) error

ExportToFile 将泛型数据列表按模板填充到输出文件。

func Import

func Import[T any](tpl Template, reader io.Reader) ([]T, error)

Import 从 reader 读取 Excel,按模板表头映射解析为泛型列表。

func ImportFromFile

func ImportFromFile[T any](tpl Template, inputPath string) ([]T, error)

ImportFromFile 从 Excel 文件按模板表头映射解析为泛型列表。

Types

type Template

type Template struct {
	// FilePath 模板文件路径(导出时打开;导入时作为表头参考)。
	FilePath string
	// SheetName 工作表名(默认 "Sheet1")。
	SheetName string
	// HeaderRow 表头行号(1-based,默认 1)。
	HeaderRow int
	// DataStartRow 数据起始行号(1-based,默认 2)。
	DataStartRow int
}

Template 模板配置:用户提供的 .xlsx 文件(已调好样式/格式),gbx 填充数据区域。

Jump to

Keyboard shortcuts

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