wordparser

package
v1.4.0-alpha0407 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileExtension

func GetFileExtension(mimeType string) string

GetFileExtension 根据MIME类型获取文件扩展名

Types

type ChartContent

type ChartContent struct {
	Type      string      // 图表类型
	Data      []byte      // 图表数据
	ChartData interface{} // 解析后的图表数据
}

ChartContent 图表节点内容

type Document

type Document struct {
	XMLName xml.Name `xml:"document"`
	Body    struct {
		Elements []Element `xml:",any"`
	} `xml:"body"`
}

Document 定义文档结构

type Element

type Element struct {
	XMLName  xml.Name
	Content  string     `xml:",chardata"`
	Attrs    []xml.Attr `xml:",any,attr"`
	Children []Element  `xml:",any"`
}

Element 定义文档元素

type File

type File struct {
	Name       string            // 文件名
	Data       []byte            // 文件内容(兼容旧版本)
	Content    string            // 文本内容
	BinaryData []byte            // 二进制数据
	FileName   string            // 文件名(用于二进制文件)
	Metadata   map[string]string // 附加信息
}

File 定义文件对象

type FileType

type FileType string

FileType 定义文件类型

const (
	FileTypeText      FileType = "text"
	FileTypeTable     FileType = "table"
	FileTypeImage     FileType = "image"
	FileTypeChart     FileType = "chart"
	FileTypePDF       FileType = "pdf"
	FileTypeOLE       FileType = "ole"
	FileTypeVBA       FileType = "vba"
	FileTypeVideo     FileType = "video"
	FileTypeVideoData FileType = "videodata" // 视频二进制数据
)

type ImageContent

type ImageContent struct {
	Data     []byte
	MimeType string
	Name     string
}

ImageContent 图片节点内容

type NodeType

type NodeType int

NodeType 定义节点类型

const (
	TextNode NodeType = iota
	TableNode
	ImageNode
	ChartNode
	PDFNode
	OLENode
	VBANode
)

type OLEContent

type OLEContent struct {
	Type string // 如 "PowerPoint.Show"
	Data []byte
	Name string
}

OLEContent OLE对象内容

type PDFContent

type PDFContent struct {
	Data []byte
	Name string
}

PDFContent PDF附件内容

type Relationship

type Relationship struct {
	ID         string `xml:"Id,attr"`
	Type       string `xml:"Type,attr"`
	Target     string `xml:"Target,attr"`
	TargetMode string `xml:"TargetMode,attr"`
}

Relationship 定义文档关系

type Relationships

type Relationships struct {
	XMLName      xml.Name       `xml:"Relationships"`
	Relationship []Relationship `xml:"Relationship"`
}

Relationships 定义文档关系集合

type TableContent

type TableContent struct {
	Rows    [][]string
	Headers []string
}

TableContent 表格节点内容

type TextContent

type TextContent struct {
	Text     string
	IsBold   bool
	IsItalic bool
	IsStrike bool
}

TextContent 文本节点内容

type VBAContent

type VBAContent struct {
	Code    string
	ModName string
}

VBAContent VBA代码内容

type WordNode

type WordNode struct {
	Type     NodeType
	Content  interface{}
	Position int
}

WordNode 定义通用节点结构

func ParseWord

func ParseWord(filePath string) ([]WordNode, error)

ParseWord 解析Word文档,返回节点数组

type WordNodeClassifier

type WordNodeClassifier struct {
	Texts  []TextContent  // 文本内容
	Tables []TableContent // Excel表格
	Images []ImageContent // 图片
	Charts []ChartContent // 图表
	PDFs   []PDFContent   // PDF附件
	OLEs   []OLEContent   // OLE对象(如PPT)
	VBAs   []VBAContent   // 宏代码(VBA)
}

WordNodeClassifier 用于存储分类后的节点

func ClassifyNodes

func ClassifyNodes(nodes []WordNode) *WordNodeClassifier

ClassifyNodes 将解析结果分类

func (*WordNodeClassifier) DumpToFiles

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

DumpToFiles 将 WordNodeClassifier 对象转换为文件对象

func (*WordNodeClassifier) GetAllTables

func (c *WordNodeClassifier) GetAllTables() []string

GetAllTables 获取所有表格内容的字符串表示

func (*WordNodeClassifier) GetAllText

func (c *WordNodeClassifier) GetAllText() string

GetAllText 获取所有文本内容

func (*WordNodeClassifier) GetChartInfo

func (c *WordNodeClassifier) GetChartInfo() []map[string]string

GetChartInfo 获取所有图表信息

func (*WordNodeClassifier) GetImageInfo

func (c *WordNodeClassifier) GetImageInfo() []map[string]string

GetImageInfo 获取所有图片信息

func (*WordNodeClassifier) GetOLEInfo

func (c *WordNodeClassifier) GetOLEInfo() []map[string]string

GetOLEInfo 获取所有OLE对象信息

func (*WordNodeClassifier) GetPDFInfo

func (c *WordNodeClassifier) GetPDFInfo() []map[string]string

GetPDFInfo 获取所有PDF附件信息

func (*WordNodeClassifier) GetStatistics

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

GetStatistics 获取分类统计信息

func (*WordNodeClassifier) GetVBAInfo

func (c *WordNodeClassifier) GetVBAInfo() []map[string]string

GetVBAInfo 获取所有VBA代码信息

func (*WordNodeClassifier) PrintSummary

func (c *WordNodeClassifier) PrintSummary() string

PrintSummary 打印文档内容摘要

Jump to

Keyboard shortcuts

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