pptparser

package
v1.4.4-beta14 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypesURI = "[Content_Types].xml"
	PackageURI      = "/"
)

OPC related constants

View Source
const (
	ExternalNode string = "external"   // 外部节点
	ImageNode    string = "image/png"  // 图像节点
	VideoNode    string = "video/mp4"  // 视频节点
	AudioNode    string = "audio/mpeg" // 音频节点
	TableNode    string = "table"      // 表格节点
	TextNode     string = "text"       // 文本节点
	CommentNode  string = "comment"    // 批注节点
	SlideNode    string = "slide"      // 幻灯片节点
	NoteNode     string = "note"       // 备注节点
)

Variables

This section is empty.

Functions

func ParsePPT

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

ParsePPT 解析PPT文件并返回分类好的内容

Types

type AnimationContent

type AnimationContent struct {
	SlideNumber int               // 幻灯片编号
	Sequence    int               // 动画序号
	Effect      string            // 动画效果
	TargetID    string            // 动画目标元素ID
	Duration    string            // 动画持续时间
	Delay       string            // 动画延迟时间
	Metadata    map[string]string // 元数据
}

AnimationContent 表示动画内容

type AudioContent

type AudioContent struct {
	SlideNumber int               // 幻灯片编号
	Content     []byte            // 音频内容
	Path        string            // 音频在PPT中的路径
	Format      string            // 音频格式
	Duration    string            // 音频持续时间
	AutoPlay    bool              // 是否自动播放
	Metadata    map[string]string // 元数据
}

AudioContent 表示音频内容

type ChartContent

type ChartContent struct {
	SlideNumber int               // 幻灯片编号
	Type        string            // 图表类型
	Title       string            // 图表标题
	Data        [][]string        // 图表数据
	Position    string            // 位置信息
	Metadata    map[string]string // 元数据
}

ChartContent 表示图表内容

type CommentContent

type CommentContent struct {
	SlideNumber int    // 幻灯片编号
	Author      string // 作者名称
	Text        string // 批注内容
	Date        string // 批注日期
	Position    string // 位置信息
}

CommentContent 表示批注内容

type ContentTypeMap

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

ContentTypeMap maps part names to content types

func NewContentTypeMap

func NewContentTypeMap(overrides, defaults map[string]string) *ContentTypeMap

NewContentTypeMap creates a new content type map

func (*ContentTypeMap) FromXML

func (c *ContentTypeMap) FromXML(contentTypesXML []byte) error

FromXML creates a ContentTypeMap from XML

func (*ContentTypeMap) GetContentType

func (c *ContentTypeMap) GetContentType(partname PackURI) (string, error)

GetContentType returns the content type for a part

type ImageContent

type ImageContent struct {
	SlideNumber int               // 幻灯片编号
	Content     []byte            // 图像内容
	Path        string            // 图像在PPT中的路径
	Alt         string            // 替代文本
	Position    string            // 位置信息
	Size        string            // 尺寸信息
	Metadata    map[string]string // 元数据
}

ImageContent 表示图像内容

type MacroContent

type MacroContent struct {
	Name string // 宏名称
	Code string // 宏代码
	Type string // 宏类型
}

MacroContent 表示宏/VBA内容

type MasterSlideContent

type MasterSlideContent struct {
	Name     string            // 母版名称
	Elements []interface{}     // 母版中的元素
	Metadata map[string]string // 元数据
}

MasterSlideContent 表示母版内容

type NoteContent

type NoteContent struct {
	SlideNumber int    // 幻灯片编号
	Text        string // 备注内容
}

NoteContent 表示备注内容

type OpcPackage

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

OpcPackage represents a PPTX package

func NewOpcPackage

func NewOpcPackage(pkgFile interface{}) *OpcPackage

NewOpcPackage creates a new package

func OpenOpcPackage

func OpenOpcPackage(pkgFile interface{}) (*OpcPackage, error)

Open opens a package from a file

func (*OpcPackage) IterParts

func (p *OpcPackage) IterParts() []*Part

IterParts iterates over all parts in the package

func (*OpcPackage) MainDocumentPart

func (p *OpcPackage) MainDocumentPart() (*Part, error)

MainDocumentPart returns the main document part

func (*OpcPackage) PartRelatedBy

func (p *OpcPackage) PartRelatedBy(relType RelationshipType) (*Part, error)

PartRelatedBy returns the part related by the given relationship type

func (*OpcPackage) Rels

func (p *OpcPackage) Rels() *Relationships

Rels returns the package relationships

func (*OpcPackage) Save

func (p *OpcPackage) Save(pkgFile interface{}) error

Save saves the package to a file

type PPTClassifier

type PPTClassifier struct {
	Images       []*ImageContent       // 所有图像内容
	Urls         []*URLContent         // 所有URL内容
	Videos       []*VideoContent       // 所有视频内容
	Slides       []*SlideContent       // 所有幻灯片内容
	Tables       []*TableContent       // 所有表格内容
	Audios       []*AudioContent       // 所有音频内容
	Notes        []*NoteContent        // 所有备注内容
	Texts        []*TextContent        // 所有文本内容
	Comments     []*CommentContent     // 所有批注内容
	MasterSlides []*MasterSlideContent // 所有母版内容
	Themes       []*ThemeContent       // 所有主题内容
	Animations   []*AnimationContent   // 所有动画内容
	Transitions  []*TransitionContent  // 所有转场效果内容
	Macros       []*MacroContent       // 所有宏内容
}

PPTClassifier 用于分类PPT节点

func ClassifyNodes

func ClassifyNodes(nodes []PPTNode) *PPTClassifier

ClassifyNodes 对PPT节点进行分类

func (*PPTClassifier) DumpToFiles

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

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

type PPTNode

type PPTNode struct {
	Type    string      // 节点类型
	Content interface{} // 节点内容
}

PPTNode 表示 PPT 文档中的一个节点

func ParsePPTX

func ParsePPTX(content []byte) ([]PPTNode, error)

ParsePPTX parses a PPTX file and returns the nodes

type PPTXParser

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

PPTXParser is the parser for PPTX files using OPC (Open Packaging Convention)

func (*PPTXParser) Parse

func (p *PPTXParser) Parse() ([]PPTNode, error)

Parse parses the PPTX file

type PackURI

type PackURI struct {
	URI string
}

PackURI represents a package part URI

func NewPackURI

func NewPackURI(uri string) PackURI

NewPackURI creates a new PackURI

func (PackURI) BaseURI

func (p PackURI) BaseURI() string

BaseURI returns the base URI of the PackURI

func (PackURI) Ext

func (p PackURI) Ext() string

Ext returns the extension of the URI

func (PackURI) FromRelRef

func (p PackURI) FromRelRef(baseURI, target string) PackURI

FromRelRef creates a PackURI from a relative reference

func (PackURI) RelativeRef

func (p PackURI) RelativeRef(baseURI string) string

RelativeRef returns the relative reference of this URI to a base URI

type PackageLoader

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

PackageLoader loads a package from a file

func NewPackageLoader

func NewPackageLoader(pkgFile interface{}, pkg *OpcPackage) *PackageLoader

NewPackageLoader creates a new package loader

func (*PackageLoader) Load

func (p *PackageLoader) Load() error

Load loads the package

type Part

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

Part represents a part in the package

func NewPart

func NewPart(partname PackURI, contentType string, pkg *OpcPackage, blob []byte) *Part

NewPart creates a new part

func (*Part) Blob

func (p *Part) Blob() []byte

Blob returns the blob data

func (*Part) ContentType

func (p *Part) ContentType() string

ContentType returns the content type

func (*Part) LoadRelsFromXML

func (p *Part) LoadRelsFromXML(xml []byte, parts map[PackURI]*Part) error

LoadRelsFromXML loads relationships from XML

func (*Part) Package

func (p *Part) Package() *OpcPackage

Package returns the package

func (*Part) PartRelatedBy

func (p *Part) PartRelatedBy(relType RelationshipType) (*Part, error)

PartRelatedBy returns the part related by the given relationship type

func (*Part) Partname

func (p *Part) Partname() PackURI

Partname returns the part name

func (*Part) RelatedPart

func (p *Part) RelatedPart(rID string) (*Part, error)

RelatedPart returns the related part with the given relationship ID

func (*Part) Rels

func (p *Part) Rels() *Relationships

Rels returns the relationships

func (*Part) SetBlob

func (p *Part) SetBlob(blob []byte)

SetBlob sets the blob data

func (*Part) SetPartname

func (p *Part) SetPartname(partname PackURI)

SetPartname sets the part name

type Relationship

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

Relationship represents a relationship between parts

func NewRelationship

func NewRelationship(baseURI, rID string, relType RelationshipType, targetMode RelationshipTargetMode, target interface{}) *Relationship

NewRelationship creates a new relationship

func (*Relationship) IsExternal

func (r *Relationship) IsExternal() bool

IsExternal returns true if the relationship is external

func (*Relationship) RID

func (r *Relationship) RID() string

RID returns the relationship ID

func (*Relationship) RelType

func (r *Relationship) RelType() RelationshipType

RelType returns the relationship type

func (*Relationship) TargetPart

func (r *Relationship) TargetPart() (*Part, error)

TargetPart returns the target part of the relationship

func (*Relationship) TargetRef

func (r *Relationship) TargetRef() string

TargetRef returns the target reference of the relationship

type RelationshipTargetMode

type RelationshipTargetMode string

RelationshipTargetMode defines the target mode for relationships

const (
	RelationshipTargetModeInternal RelationshipTargetMode = "Internal"
	RelationshipTargetModeExternal RelationshipTargetMode = "External"
)

type RelationshipType

type RelationshipType string

RelationshipType defines common relationship types

const (
	RelationshipTypeOfficeDocument RelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
)

type Relationships

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

Relationships represents a collection of relationships

func NewRelationships

func NewRelationships(baseURI string) *Relationships

NewRelationships creates a new relationships collection

func (*Relationships) Get

func (r *Relationships) Get(rID string) (*Relationship, bool)

Get returns the relationship with the given ID

func (*Relationships) GetOrAdd

func (r *Relationships) GetOrAdd(relType RelationshipType, targetPart *Part) string

GetOrAdd adds a relationship or returns an existing one

func (*Relationships) GetOrAddExtRel

func (r *Relationships) GetOrAddExtRel(relType RelationshipType, targetRef string) string

GetOrAddExtRel adds an external relationship or returns an existing one

func (*Relationships) Keys

func (r *Relationships) Keys() []string

Keys returns the keys of the relationships collection

func (*Relationships) Len

func (r *Relationships) Len() int

Len returns the number of relationships

func (*Relationships) LoadFromXML

func (r *Relationships) LoadFromXML(baseURI string, relXML []byte, parts map[PackURI]*Part) error

LoadFromXML loads relationships from XML

func (*Relationships) PartWithRelType

func (r *Relationships) PartWithRelType(relType RelationshipType) (*Part, error)

PartWithRelType returns the part with the given relationship type

func (*Relationships) Pop

func (r *Relationships) Pop(rID string) (*Relationship, error)

Pop removes a relationship and returns it

func (*Relationships) ToXML

func (r *Relationships) ToXML() ([]byte, error)

ToXML serializes relationships to XML

func (*Relationships) Values

func (r *Relationships) Values() []*Relationship

Values returns the values of the relationships collection

type ShapeContent

type ShapeContent struct {
	SlideNumber int               // 幻灯片编号
	Type        string            // 形状类型
	Text        string            // 形状中的文本
	Position    string            // 位置信息
	Style       string            // 形状样式
	Metadata    map[string]string // 元数据
}

ShapeContent 表示形状内容

type SldId

type SldId struct {
	ID  string
	RID string
}

type SlideContent

type SlideContent struct {
	SlideNumber int               // 幻灯片编号
	Title       string            // 幻灯片标题
	Layout      string            // 幻灯片布局
	Nodes       []PPTNode         //
	Metadata    map[string]string // 元数据
}

SlideContent 表示幻灯片内容

type TableContent

type TableContent struct {
	SlideNumber int               // 幻灯片编号
	Headers     []string          // 表头
	Rows        [][]string        // 数据行
	Position    string            // 位置信息
	Style       string            // 表格样式
	Metadata    map[string]string // 元数据
}

TableContent 表示表格内容

type TextContent

type TextContent struct {
	SlideNumber int               // 幻灯片编号
	Text        string            // 文本内容
	Position    string            // 位置信息
	FontInfo    map[string]string // 字体信息
	IsTitle     bool              // 是否为标题
	Level       int               // 列表级别,0表示不是列表项
}

TextContent 表示文本内容

type ThemeContent

type ThemeContent struct {
	Name       string            // 主题名称
	Colors     []string          // 主题颜色
	Fonts      []string          // 主题字体
	Background string            // 主题背景
	Metadata   map[string]string // 元数据
}

ThemeContent 表示主题内容

type TransitionContent

type TransitionContent struct {
	SlideNumber int    // 幻灯片编号
	Type        string // 转场类型
	Duration    string // 转场持续时间
	Sound       string // 转场声音
	Trigger     string // 转场触发方式
}

TransitionContent 表示转场效果内容

type URLContent

type URLContent struct {
	SlideNumber int               // 幻灯片编号
	URL         string            // URL内容
	DisplayText string            // 显示文本
	Position    string            // 位置信息
	Metadata    map[string]string // 元数据
}

URLContent 表示URL内容

type VideoContent

type VideoContent struct {
	SlideNumber int               // 幻灯片编号
	Content     []byte            // 视频内容
	Path        string            // 视频在PPT中的路径
	Position    string            // 位置信息
	Size        string            // 尺寸信息
	Format      string            // 视频格式
	Duration    string            // 视频持续时间
	BinaryData  []byte            // 视频二进制数据
	Metadata    map[string]string // 元数据
}

VideoContent 表示视频内容

type XmlPart

type XmlPart struct {
	*Part
	// contains filtered or unexported fields
}

XmlPart represents a part containing XML

func NewXmlPart

func NewXmlPart(partname PackURI, contentType string, pkg *OpcPackage, element interface{}) *XmlPart

NewXmlPart creates a new XML part

func (*XmlPart) Blob

func (p *XmlPart) Blob() []byte

Blob returns the serialized XML

func (*XmlPart) Element

func (p *XmlPart) Element() interface{}

Element returns the XML element

Jump to

Keyboard shortcuts

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