excelparser

package
v1.4.4-beta4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExcelExports = map[string]interface{}{

	"NewFile": CreateExcelFile,
	"Save":    SaveExcelFile,

	"NewSheet":        NewSheet,
	"DeleteSheet":     DeleteSheet,
	"SetSheetVisible": SetSheetVisible,

	"WriteCell":  WriteCell,
	"SetFormula": SetFormula,

	"SetCellStyle": SetCellStyle,
	"CreateStyle":  CreateStyle,

	"InsertImage": InsertImage,

	"Parse":         ParseExcelFile,
	"ClassifyNodes": ClassifyNodes,
}

ExcelExports 导出给yak脚本使用的Excel操作函数

Functions

func CreateExcelFile

func CreateExcelFile() *excelize.File

CreateExcelFile 创建新的Excel文件

func CreateStyle

func CreateStyle(file *excelize.File, style *excelize.Style) (int, error)

CreateStyle 创建样式

func DeleteSheet

func DeleteSheet(file *excelize.File, name string) error

DeleteSheet 删除工作表

func InsertImage

func InsertImage(file *excelize.File, sheet, cell, picture string) error

InsertImage 插入图片

func NewSheet

func NewSheet(file *excelize.File, name string) (int, error)

NewSheet 创建新工作表

func ParseExcel

func ParseExcel(filePath string) (map[string][]types.File, error)

ParseExcel 解析 Excel 文件,将内部函数重定向到ParseExcelFile

func SaveExcelFile

func SaveExcelFile(file *excelize.File, path string) error

SaveExcelFile 保存Excel文件

func SetCellStyle

func SetCellStyle(file *excelize.File, sheet, hCell, vCell string, styleID int) error

SetCellStyle 设置单元格样式

func SetFormula

func SetFormula(file *excelize.File, sheet, cell, formula string) error

SetFormula 设置单元格公式

func SetSheetVisible

func SetSheetVisible(file *excelize.File, name string, visible bool) error

SetSheetVisible 设置工作表可见性

func WriteCell

func WriteCell(file *excelize.File, sheet, cell string, value interface{}) error

WriteCell 向指定单元格写入数据

Types

type CommentContent

type CommentContent struct {
	SheetName string // 工作表名称
	Cell      string // 单元格位置
	Author    string // 作者名称
	Text      string // 批注内容
}

CommentContent 表示批注内容

type CondRuleContent

type CondRuleContent struct {
	SheetName   string // 工作表名称
	Range       string // 应用区域
	Type        string // 规则类型
	Formula     string // 规则公式
	FormatStyle string // 格式样式
}

CondRuleContent 表示条件规则内容

type DataConnContent

type DataConnContent struct {
	Name             string // 连接名称
	Description      string // 连接描述
	ConnectionString string // 连接字符串
	Command          string // 命令内容
	Type             string // 连接类型
}

DataConnContent 表示外部数据连接内容

type ExcelNode

type ExcelNode struct {
	Type    NodeType    // 节点类型
	Content interface{} // 节点内容
}

ExcelNode 表示 Excel 文档中的一个节点

func ParseExcelFile

func ParseExcelFile(filePath string) ([]ExcelNode, error)

ParseExcelFile 解析 Excel 文件,返回所有工作表中的内容

type ExcelNodeClassifier

type ExcelNodeClassifier struct {
	Tables       []TableContent       // 表格内容
	Texts        []TextContent        // 文本内容
	URLs         []URLContent         // URL内容
	Formulas     []FormulaContent     // 公式内容
	Comments     []CommentContent     // 批注内容
	DataConns    []DataConnContent    // 外部数据连接
	PowerQueries []PowerQueryContent  // Power Query脚本
	VBAs         []VBAContent         // VBA宏
	HiddenSheets []HiddenSheetContent // 隐藏工作表
	NameDefs     []NameDefContent     // 名称管理器定义
	CondRules    []CondRuleContent    // 条件规则
}

ExcelNodeClassifier 用于存储分类后的节点

func ClassifyNodes

func ClassifyNodes(nodes []ExcelNode) *ExcelNodeClassifier

ClassifyNodes 将解析结果分类

func (*ExcelNodeClassifier) DumpToFiles

func (c *ExcelNodeClassifier) DumpToFiles() map[string][]types.File

DumpToFiles 将分类后的节点转换为文件

func (*ExcelNodeClassifier) GetStatistics

func (c *ExcelNodeClassifier) GetStatistics() map[string]int

GetStatistics 获取分类统计信息

func (*ExcelNodeClassifier) PrintSummary

func (c *ExcelNodeClassifier) PrintSummary() string

PrintSummary 打印文档内容摘要

type ExcelNodeDumper

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

ExcelNodeDumper 用于将 Excel 节点转换为文件 注意:这是一个简单实现,推荐使用classifier.go中的方法 此代码保留是为了向后兼容

func NewDumper

func NewDumper(nodes []ExcelNode) *ExcelNodeDumper

NewDumper 创建一个新的 dumper 注意:推荐使用classifier.go中的方法 此代码保留是为了向后兼容

func (*ExcelNodeDumper) DumpToFiles

func (d *ExcelNodeDumper) DumpToFiles() map[string][]types.File

DumpToFiles 将节点转换为文件 注意:推荐使用classifier.go中的方法 此代码保留是为了向后兼容

type FileType

type FileType string

FileType 定义文件类型

const (
	FileTypeText        FileType = "text"        // 文本内容
	FileTypeTable       FileType = "table"       // 表格内容
	FileTypeURL         FileType = "url"         // URL内容
	FileTypeFormula     FileType = "formula"     // 公式内容
	FileTypeComment     FileType = "comment"     // 批注内容
	FileTypeDataConn    FileType = "dataconn"    // 外部数据连接
	FileTypePowerQuery  FileType = "powerquery"  // Power Query脚本
	FileTypeVBA         FileType = "vba"         // VBA宏
	FileTypeHiddenSheet FileType = "hiddensheet" // 隐藏工作表
	FileTypeNameDef     FileType = "namedef"     // 名称管理器定义
	FileTypeCondRule    FileType = "condrule"    // 条件规则
)

type FormulaContent

type FormulaContent struct {
	SheetName string // 工作表名称
	Cell      string // 单元格位置
	Formula   string // 公式内容
	Result    string // 公式结果
}

FormulaContent 表示公式内容

type HiddenSheetContent

type HiddenSheetContent struct {
	SheetName string     // 工作表名称
	Headers   []string   // 表头
	Rows      [][]string // 数据行
	HideType  string     // 隐藏类型(普通隐藏、超隐藏)
}

HiddenSheetContent 表示隐藏工作表内容

type NameDefContent

type NameDefContent struct {
	Name     string // 名称
	RefersTo string // 引用内容
	Comment  string // 注释
	Scope    string // 作用域
}

NameDefContent 表示名称管理器定义内容

type NodeType

type NodeType string

NodeType 定义节点类型

const (
	TableNode       NodeType = "table"       // 表格节点
	TextNode        NodeType = "text"        // 文本节点
	URLNode         NodeType = "url"         // URL节点
	FormulaNode     NodeType = "formula"     // 公式节点
	CommentNode     NodeType = "comment"     // 批注节点
	DataConnNode    NodeType = "dataconn"    // 外部数据连接节点
	PowerQueryNode  NodeType = "powerquery"  // Power Query脚本节点
	VBANode         NodeType = "vba"         // VBA宏节点
	HiddenSheetNode NodeType = "hiddensheet" // 隐藏工作表节点
	NameDefNode     NodeType = "namedef"     // 名称管理器定义节点
	CondRuleNode    NodeType = "condrule"    // 条件规则节点
)

type PowerQueryContent

type PowerQueryContent struct {
	Name   string // 查询名称
	Script string // 脚本内容
	Source string // 数据源
}

PowerQueryContent 表示Power Query脚本内容

type TableContent

type TableContent struct {
	SheetName string            // 工作表名称
	Headers   []string          // 表头
	Rows      [][]string        // 数据行
	Metadata  map[string]string // 元数据
}

TableContent 表示表格内容

type TextContent

type TextContent struct {
	SheetName string // 工作表名称
	Cell      string // 单元格位置
	Text      string // 文本内容
}

TextContent 表示文本内容

type URLContent

type URLContent struct {
	SheetName string // 工作表名称
	Cell      string // 单元格位置
	URL       string // URL内容
}

URLContent 表示URL内容

type VBAContent

type VBAContent struct {
	ModuleName string // 模块名称
	Code       string // 代码内容
	Type       string // 模块类型
}

VBAContent 表示VBA宏内容

Jump to

Keyboard shortcuts

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