docx

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	Children []BodyChild
}

Body 对应主文档中的 <w:body>...</w:body>

func (*Body) String

func (b *Body) String() string

func (*Body) UnmarshalXML

func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 解析<body>元素

type BodyChild

type BodyChild interface {
	String() string
	TypeName() BodyChildType
}

BodyChild <body>中的元素:p、tbl、sectPr

type BodyChildType

type BodyChildType uint8
const (
	BodyTypeParagraph BodyChildType = iota
	BodyTypeTable
	BodyTypeSecPr
)

type Break

type Break struct {
	Val *bool
}

func (*Break) String

func (b *Break) String() string

func (*Break) TypeName

func (b *Break) TypeName() RunChildType

type Color

type Color struct {
	// 字体颜色值,如 D4F4F2,前面不带#号
	Value string
	// 字体的主题颜色,如运用了主题,以主题为主
	Theme string
}

Color 字体颜色

type ContentTypes

type ContentTypes struct {
	DefaultItems []ContentTypesDefaultItem  `xml:"Default"`
	OverrideItem []ContentTypesOverrideItem `xml:"Override"`
}

type ContentTypesDefaultItem

type ContentTypesDefaultItem struct {
	Extension   string `xml:"Extension,attr"`
	ContentType string `xml:"ContentType,attr"`
}

type ContentTypesOverrideItem

type ContentTypesOverrideItem struct {
	PartName    string `xml:"PartName,attr"`
	ContentType string `xml:"ContentType,attr"`
}

type CoreProperties

type CoreProperties struct {
	Created        string `xml:"http://purl.org/dc/terms/ created"`
	Creator        string `xml:"http://purl.org/dc/elements/1.1/ creator"`
	LastModifiedBy string `xml:"http://schemas.openxmlformats.org/pkg/2006/metadata/core-properties lastModifiedBy"`
	Modified       string `xml:"http://purl.org/dc/terms/ modified"`
	Revision       int    `xml:"http://schemas.openxmlformats.org/pkg/2006/metadata/core-properties revision"`
}

CoreProperties is the `Application-Defined File Properties part` => docProps/core.xml

type CustomProperties

type CustomProperties struct {
	Xmlns    string               `xml:"xmlns,attr"`
	Children []CustomPropertyItem `xml:"property"`
}

CustomProperties is the `Application-Defined File Properties part` => docProps/custom.xml

type CustomPropertyItem

type CustomPropertyItem struct {
	Fmtid  string `xml:"fmtid,attr"`
	Pid    string `xml:"pid,attr"`
	Name   string `xml:"name,attr"`
	Lpwstr string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes lpwstr"`
}

CustomPropertyItem is the item of the docProps/custom.xml file

type DocDefaults

type DocDefaults struct {
	RPrDefault *RunProperty
	PPrDefault *ParagraphProperty
}

type Document

type Document struct {
	Body *Body `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main body"`
}

Document 代表了word整个文档

type Docx

type Docx struct {
	PackageRelationship *PackageRelationshipItem
	CoreProperties      *CoreProperties
	CustomProperties    *CustomProperties
	ExtendedProperties  *ExtendedProperties
	ContentTypes        *ContentTypes
	PartRelationship    *PartRelationship
	//FontTable           *FontTable
	//Header              *Header
	//Numbering           *Numbering
	//Settings            *Settings
	Styles *Styles
	//Footer              *Footer
	Document *Document
}

Docx 代表了word整个文档

func OpenDocxFile

func OpenDocxFile(filename string) (*Docx, error)

type ExtendedProperties

type ExtendedProperties struct {
	Template             string `xml:"Template"`
	Pages                int    `xml:"Pages"`
	Words                int    `xml:"Words"`
	Characters           int    `xml:"Characters"`
	Lines                int    `xml:"Lines"`
	Paragraphs           int    `xml:"Paragraphs"`
	TotalTime            int    `xml:"TotalTime"`
	ScaleCrop            bool   `xml:"ScaleCrop"`
	LinksUpToDate        bool   `xml:"LinksUpToDate"`
	CharactersWithSpaces int    `xml:"CharactersWithSpaces"`
	Application          string `xml:"Application"`
	DocSecurity          int    `xml:"DocSecurity"`
}

ExtendedProperties is the `Application-Defined File Properties part` => docProps/app.xml

type Indent

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

Indent 设置段落缩进

This element specifies the set of indentation properties applied to the current paragraph

type Language

type Language struct {
	// 指定在处理使用拉丁字符的运行内容时(由运行内容的Unicode字符值决定)应用于检查拼写和语法(如果请求)的语言
	Value string
	// 指定在处理使用复杂脚本字符的运行内容时应使用的语言,由运行内容的Unicode字符值决定。
	Bidi string
	// 指定在处理使用东亚字符的运行内容时应使用的语言
	EastAsian string
}

Language 字体语言

type LatentStyles

type LatentStyles struct {
	Count             int
	DefQFormat        bool
	DefUnhideWhenUsed bool
	DefSemiHidden     bool
	DefUIPriority     int
	DefLockedState    bool
	LsdExceptions     []LsdException
}

type LsdException

type LsdException struct {
	Locked         bool
	QFormat        bool
	UnhideWhenUsed bool
	UiPriority     int
	SemiHidden     bool
	Name           string
}

type PackageRelationshipItem

type PackageRelationshipItem struct {
	Id     string `xml:"Id,attr"`
	Type   string `xml:"TypeName,attr"`
	Target string `xml:"Target,attr"`
}

type PackageRelationships

type PackageRelationships struct {
	Xmlns    string                    `xml:"xmlns,attr"`
	Children []PackageRelationshipItem `xml:"PackageRelationshipItem"`
}

PackageRelationships => ./rels/.rels

type Paragraph

type Paragraph struct {
	Children     []ParagraphChild
	Property     *ParagraphProperty
	HasNumbering bool
}

func (*Paragraph) String

func (p *Paragraph) String() string

func (*Paragraph) TypeName

func (p *Paragraph) TypeName() BodyChildType

func (*Paragraph) UnmarshalXML

func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type ParagraphChild

type ParagraphChild interface {
	String() string
	TypeName() ParagraphChildType
}

type ParagraphChildType

type ParagraphChildType uint8
const (
	ParagraphTypeRun ParagraphChildType = iota
	ParagraphTypePPr
)

type ParagraphProperty

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

ParagraphProperty 段落属性

func (*ParagraphProperty) Bidi

func (pPr *ParagraphProperty) Bidi() *bool

func (*ParagraphProperty) String

func (pPr *ParagraphProperty) String() string

func (*ParagraphProperty) UnmarshalXML

func (pPr *ParagraphProperty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type PartRelationship

type PartRelationship struct {
}

type Run

type Run struct {
	RunProperty     *RunProperty
	Children        []RunChild
	ParentParagraph *Paragraph
}

func (*Run) String

func (r *Run) String() string

func (*Run) TypeName

func (r *Run) TypeName() ParagraphChildType

func (*Run) UnmarshalXML

func (r *Run) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML 解析<w:r>...</w:r>标签下的内容

type RunChild

type RunChild interface {
	String() string
	TypeName() RunChildType
}

type RunChildType

type RunChildType uint8
const (
	RunTypeText RunChildType = iota
	RunTypeRpr
	RunTypeBreak
)

type RunFonts

type RunFonts struct {
	// 默认提示所用的子图
	Hint string
	// 处理Ascii字符时所使用的字体
	Ascii string
	// 处理 High ANSI 字符时所使用的字体
	HAnsi string
	// 处理东南亚 East Asian 文字所使用的字体,包括中文
	EastAsia string
	// 处理 Complex Script 字符时所使用的字体
	Cs string
	// Ascii字符所使用的主题
	AsciiTheme string
	// High ANSI字符所使用的主题
	HAnsiTheme string
	// 东南亚文字所使用的主题
	EastAsiaTheme string
}

RunFonts 最多有4种字体槽

type RunProperty

type RunProperty struct {
	// contains filtered or unexported fields
}
RunProperty Run的属性,与 XML 文档对应

This element specifies a set of run properties which shall be applied to the contents of the parentRun run after all style formatting has been applied to the text. These properties are defined as direct formatting, since they are directly applied to the run and supersede any formatting from styles

func (*RunProperty) Bold

func (rPr *RunProperty) Bold() *bool

func (*RunProperty) BoldCs

func (rPr *RunProperty) BoldCs() *bool

func (*RunProperty) Color

func (rPr *RunProperty) Color() *Color

func (*RunProperty) ComplexScript

func (rPr *RunProperty) ComplexScript() *bool

func (*RunProperty) DoubleStrikethrough

func (rPr *RunProperty) DoubleStrikethrough() *bool

func (*RunProperty) EmphasisMark

func (rPr *RunProperty) EmphasisMark() *string

func (*RunProperty) FontKerning

func (rPr *RunProperty) FontKerning() *int

func (*RunProperty) Fonts

func (rPr *RunProperty) Fonts() *RunFonts

func (*RunProperty) Imprint

func (rPr *RunProperty) Imprint() *bool

func (*RunProperty) Italics

func (rPr *RunProperty) Italics() *bool

func (*RunProperty) ItalicsCs

func (rPr *RunProperty) ItalicsCs() *bool

func (*RunProperty) Lang

func (rPr *RunProperty) Lang() *Language

func (*RunProperty) Outline

func (rPr *RunProperty) Outline() *bool

func (*RunProperty) Position

func (rPr *RunProperty) Position() *int

func (*RunProperty) Size

func (rPr *RunProperty) Size() *int

func (*RunProperty) SizeCs

func (rPr *RunProperty) SizeCs() *int

func (*RunProperty) String

func (rPr *RunProperty) String() string

String 输出为字符串

func (*RunProperty) UnmarshalXML

func (rPr *RunProperty) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML 解析XML文档

type SectionProperty

type SectionProperty struct {
}

func (*SectionProperty) String

func (s *SectionProperty) String() string

func (*SectionProperty) TypeName

func (s *SectionProperty) TypeName() BodyChildType

type StyleItem

type StyleItem struct {
	TypeFor string
	Default bool
	//rStyleId string  // it has putted into the key of the map
	Name         string
	QFormat      *bool
	AutoRedefine *bool
	UiPriority   int
	BasedOn      string
	Next         string
	RPr          *RunProperty
	PPr          *ParagraphProperty
}

type Styles

type Styles struct {
	DocDefaults  DocDefaults
	LatentStyles LatentStyles
	StyleSheets  map[string]StyleItem
}

func (*Styles) UnmarshalXML

func (s *Styles) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

type Table

type Table struct {
	Rows []TableRow
}

func (*Table) String

func (t *Table) String() string

func (*Table) TypeName

func (p *Table) TypeName() BodyChildType

func (*Table) UnmarshalXML

func (tbl *Table) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TableCell

type TableCell struct {
	Property TableCellProperty
	Children []BodyChild
}

func (*TableCell) String

func (c *TableCell) String() string

func (*TableCell) UnmarshalXML

func (c *TableCell) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TableCellProperty

type TableCellProperty struct {
	// Table Cell Width,如果为小于0的值,则代表未取到该值
	Tcw float64
	// dxa |  pct(百分比)
	TcwType string
}

func (*TableCellProperty) String

func (c *TableCellProperty) String() string

func (*TableCellProperty) UnmarshalXML

func (c *TableCellProperty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TableRow

type TableRow struct {
	Cells []TableCell
}

func (*TableRow) String

func (r *TableRow) String() string

func (*TableRow) UnmarshalXML

func (r *TableRow) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Text

type Text struct {
	Text  string `xml:",chardata"`
	Space string `xml:"space,attr,omitempty"`
}

func (*Text) String

func (t *Text) String() string

func (*Text) TypeName

func (t *Text) TypeName() RunChildType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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