docx

package module
v0.0.0-...-8f66e2b Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: AGPL-3.0 Imports: 19 Imported by: 2

README

Docx library

One of the most functional libraries to read and write .docx (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) files in Go.

This is a variant optimized and expanded by fumiama. The original repo is gonfva/docxlib.

Introduction

As part of my work for Basement Crowd and FromCounsel, we were in need of a basic library to manipulate (both read and write) Microsoft Word documents.

The difference with other projects is the following:

  • UniOffice is probably the most complete but it is also commercial (you need to pay). It also very complete, but too much for my needs.
  • gingfrederik/docx only allows to write.

There are also a couple of other projects kingzbauer/docx and nguyenthenguyen/docx

gingfrederik/docx was a heavy influence (the original structures and the main method come from that project).

However, those original structures didn't handle reading and extending them was particularly difficult due to Go xml parser being a bit limited including a 6 year old bug.

Additionally, my requirements go beyond the original structure and a hard fork seemed more sensible.

The plan is to evolve the library, so the API is likely to change according to my company's needs. But please do feel free to send patches, reports and PRs (or fork).

In the mean time, shared as an example in case somebody finds it useful.

The Introduction above is copied from the original repo. I had evolved that repo again to fit my needs. Here are the supported functions now.

  • Parse and save document
  • Edit text (color, size, alignment, link, ...)
  • Edit picture
  • Edit table
  • Edit shape
  • Edit canvas
  • Edit group

Quick Start

go run cmd/main/main.go -u

And you will see two files generated under pwd with the same contents as below.

p1 p2

Use Package in your Project

go get -d github.com/fumiama/go-docx@latest
Generate Document
package main

import (
	"os"
	"strings"

	"github.com/fumiama/go-docx"
)

func main() {
	w := docx.New().WithDefaultTheme()
	// add new paragraph
	para1 := w.AddParagraph()
	// add text
	para1.AddText("test").AddTab()
	para1.AddText("size").Size("44").AddTab()
	f, err := os.Create("generated.docx")
	// save to file
	if err != nil {
		panic(err)
	}
	_, err = w.WriteTo(f)
	if err != nil {
		panic(err)
	}
	err = f.Close()
	if err != nil {
		panic(err)
	}
}
Parse Document
package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/fumiama/go-docx"
)

func main() {
	readFile, err := os.Open("file2parse.docx")
	if err != nil {
		panic(err)
	}
	fileinfo, err := readFile.Stat()
	if err != nil {
		panic(err)
	}
	size := fileinfo.Size()
	doc, err := docx.Parse(readFile, size)
	if err != nil {
		panic(err)
	}
	fmt.Println("Plain text:")
	for _, it := range doc.Document.Body.Items {
		switch it.(type) {
		case *docx.Paragraph, *docx.Table: // printable
			fmt.Println(it)
		}
	}
}

License

AGPL-3.0. See LICENSE

Documentation

Overview

Package docx is one of the most functional libraries to read and write .docx (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) files in Go.

Index

Constants

View Source
const (
	XMLNS_W   = `http://schemas.openxmlformats.org/wordprocessingml/2006/main`
	XMLNS_R   = `http://schemas.openxmlformats.org/officeDocument/2006/relationships`
	XMLNS_WP  = `http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing`
	XMLNS_WPS = `http://schemas.microsoft.com/office/word/2010/wordprocessingShape`
	XMLNS_WPC = `http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas`
	XMLNS_WPG = `http://schemas.microsoft.com/office/word/2010/wordprocessingGroup`
	XMLNS_MC  = `http://schemas.openxmlformats.org/markup-compatibility/2006`

	XMLNS_O = `urn:schemas-microsoft-com:office:office`
	XMLNS_V = `urn:schemas-microsoft-com:vml`

	XMLNS_PICTURE = `http://schemas.openxmlformats.org/drawingml/2006/picture`
)
View Source
const (
	XMLNS_DRAWINGML_MAIN    = `http://schemas.openxmlformats.org/drawingml/2006/main`
	XMLNS_DRAWINGML_PICTURE = `http://schemas.openxmlformats.org/drawingml/2006/picture`
)
View Source
const (
	XMLNS_REL     = `http://schemas.openxmlformats.org/package/2006/relationships`
	REL_HYPERLINK = `http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink`
	REL_IMAGE     = `http://schemas.openxmlformats.org/officeDocument/2006/relationships/image`

	REL_TARGETMODE = "External"
)
View Source
const (
	// A4_EMU_MAX_WIDTH is the max display width of an A4 paper
	A4_EMU_MAX_WIDTH = 5274310
)
View Source
const (
	HYPERLINK_STYLE = "a3"
)
View Source
const MEDIA_FOLDER = `word/media/`

Variables

View Source
var (
	// TemplateXMLFS stores template docx files
	//go:embed xml
	//go:embed xml/default/_rels/*
	TemplateXMLFS embed.FS

	// DefaultTemplateFilesList is the files list under TemplateXMLFS/xml/default
	DefaultTemplateFilesList = []string{
		"_rels/.rels",
		"docProps/app.xml",
		"docProps/core.xml",
		"word/theme/theme1.xml",
		"word/fontTable.xml",
		"word/styles.xml",
		"[Content_Types].xml",
	}
)
View Source
var (
	// ErrRefIDNotFound cannot find such reference
	ErrRefIDNotFound = errors.New("ref id not found")
	// ErrRefTargetNotFound cannot find such target
	ErrRefTargetNotFound = errors.New("ref target not found")
)

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString 没有内存开销的转换

func GetInt

func GetInt(s string) (int, error)

GetInt from string

func GetInt64

func GetInt64(s string) (int64, error)

GetInt64 from string

func MergeAllRuns

func MergeAllRuns(_, _ *Run) bool

MergeAllRuns ...

func MergeSamePropRuns

func MergeSamePropRuns(r1, r2 *Run) bool

MergeSamePropRuns merges runs with the same properties

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes 没有内存开销的转换

Types

type AAlphaModFix

type AAlphaModFix struct {
	XMLName xml.Name `xml:"a:alphaModFix,omitempty"`
	Amount  int      `xml:"amt,attr"`
}

AAlphaModFix ...

type ABlip

type ABlip struct {
	XMLName     xml.Name `xml:"a:blip,omitempty"`
	Embed       string   `xml:"r:embed,attr"`
	Cstate      string   `xml:"cstate,attr,omitempty"`
	AlphaModFix *AAlphaModFix
}

ABlip represents the blip of a picture in a Word document.

func (*ABlip) UnmarshalXML

func (a *ABlip) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type ABlipFill

type ABlipFill struct {
	XMLName      xml.Name `xml:"a:blipFill,omitempty"`
	DPI          int      `xml:"dpi,attr"`
	RotWithShape int      `xml:"rotWithShape,attr"`

	Blip    *ABlip
	SrcRect *ASrcRect
	Tile    *ATile
}

ABlipFill represents a fill that contains a reference to an image.

func (*ABlipFill) UnmarshalXML

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

UnmarshalXML ...

type AExt

type AExt struct {
	CX int64 `xml:"cx,attr"`
	CY int64 `xml:"cy,attr"`
}

AExt is a struct representing the <a:ext> / <a:chExt> element in OpenXML, which describes the size of a shape.

type AFillRect

type AFillRect struct {
	XMLName xml.Name `xml:"a:fillRect,omitempty"`
}

AFillRect ...

type AGraphic

type AGraphic struct {
	XMLName     xml.Name `xml:"a:graphic,omitempty"`
	XMLA        string   `xml:"xmlns:a,attr,omitempty"`
	GraphicData *AGraphicData
	// contains filtered or unexported fields
}

AGraphic represents a graphic in a Word document.

func (*AGraphic) UnmarshalXML

func (a *AGraphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type AGraphicData

type AGraphicData struct {
	XMLName xml.Name `xml:"a:graphicData,omitempty"`
	URI     string   `xml:"uri,attr"`

	Pic    *Picture
	Shape  *WordprocessingShape
	Canvas *WordprocessingCanvas
	Group  *WordprocessingGroup
	// contains filtered or unexported fields
}

AGraphicData represents the data of a graphic in a Word document.

func (*AGraphicData) UnmarshalXML

func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type AGraphicFrameLocks

type AGraphicFrameLocks struct {
	XMLName        xml.Name `xml:"http://schemas.openxmlformats.org/drawingml/2006/main graphicFrameLocks,omitempty"`
	NoChangeAspect int      `xml:"noChangeAspect,attr,omitempty"`
}

AGraphicFrameLocks represents the locks applied to a graphic frame.

type AGroupShapeLocks

type AGroupShapeLocks struct {
	XMLName xml.Name `xml:"a:grpSpLocks,omitempty"`
}

AGroupShapeLocks represents the locks applied to a group shape.

type AHeadEnd

type AHeadEnd struct {
	XMLName xml.Name `xml:"a:headEnd,omitempty"`
	Type    string   `xml:"type,attr,omitempty"`
	W       string   `xml:"w,attr,omitempty"`
	Len     string   `xml:"len,attr,omitempty"`
}

AHeadEnd ...

func (*AHeadEnd) UnmarshalXML

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

UnmarshalXML ...

type ALine

type ALine struct {
	XMLName  xml.Name `xml:"a:ln,omitempty"`
	W        int64    `xml:"w,attr,omitempty"`
	Cap      string   `xml:"cap,attr,omitempty"`
	Compound string   `xml:"cmpd,attr,omitempty"`
	Align    string   `xml:"algn,attr,omitempty"`

	NoFill    *struct{} `xml:"a:noFill,omitempty"`
	SolidFill *ASolidFill
	PrstDash  *APrstDash
	Miter     *AMiter
	Round     *struct{} `xml:"a:round,omitempty"`
	HeadEnd   *AHeadEnd
	TailEnd   *ATailEnd
}

ALine represents a line element in a Word document.

func (*ALine) UnmarshalXML

func (l *ALine) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type AMiter

type AMiter struct {
	XMLName xml.Name `xml:"a:miter,omitempty"`
	Limit   string   `xml:"lim,attr"`
}

AMiter ...

type AOff

type AOff struct {
	X int64 `xml:"x,attr"`
	Y int64 `xml:"y,attr"`
}

AOff is a struct representing the <a:off> / <a:chOff> element in OpenXML, which describes the offset of a shape from its original position.

type APicLocks

type APicLocks struct {
	XMLName        xml.Name `xml:"a:picLocks,omitempty"`
	NoChangeAspect int      `xml:"noChangeAspect,attr"`
}

APicLocks represents the locks applied to a picture.

type APrstDash

type APrstDash struct {
	XMLName xml.Name `xml:"a:prstDash,omitempty"`
	Val     string   `xml:"val,attr"`
}

APrstDash ...

type APrstGeom

type APrstGeom struct {
	XMLName xml.Name  `xml:"a:prstGeom,omitempty"`
	Prst    string    `xml:"prst,attr"`
	AvLst   *struct{} `xml:"a:avLst,omitempty"`
}

APrstGeom is a struct representing the <a:prstGeom> element in OpenXML, which describes the preset shape geometry for a shape.

func (*APrstGeom) UnmarshalXML

func (a *APrstGeom) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type ASPLocks

type ASPLocks struct {
	XMLName            xml.Name `xml:"a:spLocks,omitempty"`
	NoChangeArrowheads int      `xml:"noChangeArrowheads,attr,omitempty"`
}

ASPLocks represents the locks applied to a shape.

func (*ASPLocks) UnmarshalXML

func (l *ASPLocks) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type ASolidFill

type ASolidFill struct {
	XMLName xml.Name `xml:"a:solidFill,omitempty"`
	SrgbClr *ASrgbClr
}

ASolidFill represents a solid fill of a shape or chart element.

func (*ASolidFill) UnmarshalXML

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

UnmarshalXML ...

type ASrcRect

type ASrcRect struct {
	XMLName xml.Name `xml:"a:srcRect,omitempty"`
}

ASrcRect represents the source rectangle of a tiled image fill.

type ASrgbClr

type ASrgbClr struct {
	XMLName xml.Name `xml:"a:srgbClr,omitempty"`
	Val     string   `xml:"val,attr"`
}

ASrgbClr represents an sRGB color.

type AStretch

type AStretch struct {
	XMLName  xml.Name `xml:"a:stretch,omitempty"`
	FillRect *AFillRect
}

AStretch ...

func (*AStretch) UnmarshalXML

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

UnmarshalXML ...

type ATailEnd

type ATailEnd struct {
	XMLName xml.Name `xml:"a:tailEnd,omitempty"`
	Type    string   `xml:"type,attr,omitempty"`
	W       string   `xml:"w,attr,omitempty"`
	Len     string   `xml:"len,attr,omitempty"`
}

ATailEnd ...

func (*ATailEnd) UnmarshalXML

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

UnmarshalXML ...

type ATile

type ATile struct {
	XMLName xml.Name `xml:"a:tile,omitempty"`
	TX      int64    `xml:"tx,attr"`
	TY      int64    `xml:"ty,attr"`
	SX      int64    `xml:"sx,attr"`
	SY      int64    `xml:"sy,attr"`
	Flip    string   `xml:"flip,attr"`
	Algn    string   `xml:"algn,attr"`
}

ATile represents the tiling information of a fill or border

func (*ATile) UnmarshalXML

func (t *ATile) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type AXfrm

type AXfrm struct {
	XMLName xml.Name `xml:"a:xfrm,omitempty"`
	Rot     int64    `xml:"rot,attr,omitempty"`
	FlipH   int      `xml:"flipH,attr,omitempty"`
	FlipV   int      `xml:"flipV,attr,omitempty"`
	Off     AOff     `xml:"a:off,omitempty"`
	Ext     AExt     `xml:"a:ext,omitempty"`
	ChOff   *AOff    `xml:"a:chOff,omitempty"`
	ChExt   *AExt    `xml:"a:chExt,omitempty"`
}

AXfrm is a struct representing the <a:xfrm> element in OpenXML, which describes the position and size of a shape.

func (*AXfrm) UnmarshalXML

func (a *AXfrm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type AdjustRightInd

type AdjustRightInd struct {
	XMLName xml.Name `xml:"w:adjustRightInd,omitempty"`
	Val     int      `xml:"w:val,attr"`
}

AdjustRightInd ...

type BarterRabbet

type BarterRabbet struct {
	XMLName xml.Name `xml:"w:br,omitempty"`
	Type    string   `xml:"w:type,attr,omitempty"`
}

BarterRabbet is <br> , if with type=page , add pagebreaks

func (*BarterRabbet) UnmarshalXML

func (f *BarterRabbet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type Body

type Body struct {
	Items []interface{}
	// contains filtered or unexported fields
}

Body <w:body>

func (*Body) DropDrawingOf

func (b *Body) DropDrawingOf(name string)

DropDrawingOf drops all matched drawing in body name: Canvas, Shape, Group, ShapeAndCanvas, ShapeAndCanvasAndGroup, NilPicture

func (*Body) KeepElements

func (b *Body) KeepElements(name ...string)

KeepElements keep named elems amd removes others

names: *docx.Paragraph *docx.Table

func (*Body) UnmarshalXML

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

UnmarshalXML ...

type Bold

type Bold struct {
	XMLName xml.Name `xml:"w:b,omitempty"`
}

Bold ...

type Color

type Color struct {
	XMLName xml.Name `xml:"w:color,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

Color contains the sound of music. :D I'm kidding. It contains the color

type Document

type Document struct {
	XMLName xml.Name `xml:"w:document"`
	XMLW    string   `xml:"xmlns:w,attr"`             // cannot be unmarshalled in
	XMLR    string   `xml:"xmlns:r,attr,omitempty"`   // cannot be unmarshalled in
	XMLWP   string   `xml:"xmlns:wp,attr,omitempty"`  // cannot be unmarshalled in
	XMLWPS  string   `xml:"xmlns:wps,attr,omitempty"` // cannot be unmarshalled in
	XMLWPC  string   `xml:"xmlns:wpc,attr,omitempty"` // cannot be unmarshalled in
	XMLWPG  string   `xml:"xmlns:wpg,attr,omitempty"` // cannot be unmarshalled in

	Body Body `xml:"w:body"`
}

Document <w:document>

func (*Document) UnmarshalXML

func (doc *Document) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type Docx

type Docx struct {
	Document Document // Document is word/document.xml

	io.Reader
	io.WriterTo
	// contains filtered or unexported fields
}

Docx is the structure that allow to access the internal represntation in memory of the doc (either read or about to be written)

func LoadBodyItems

func LoadBodyItems(items []interface{}, media []Media) *Docx

LoadBodyItems will load body and media to a new Docx struct. You should call UseTemplate to set a template later.

func New

func New() *Docx

New generates a new empty docx file that we can manipulate and later on, save

func Parse

func Parse(reader io.ReaderAt, size int64) (doc *Docx, err error)

Parse generates a new docx file in memory from a reader You can it invoke from a file

readFile, err := os.Open(FILE_PATH)
if err != nil {
	panic(err)
}
fileinfo, err := readFile.Stat()
if err != nil {
	panic(err)
}
size := fileinfo.Size()
doc, err := docxlib.Parse(readFile, int64(size))

but also you can invoke from a webform (BEWARE of trusting users data!!!)

func uploadFile(w http.ResponseWriter, r *http.Request) {
	r.ParseMultipartForm(10 << 20)

	file, handler, err := r.FormFile("file")
	if err != nil {
		fmt.Println("Error Retrieving the File")
		fmt.Println(err)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	defer file.Close()
	docxlib.Parse(file, handler.Size)
}

func (*Docx) AddParagraph

func (f *Docx) AddParagraph() *Paragraph

AddParagraph adds a new paragraph

func (*Docx) AddTable

func (f *Docx) AddTable(row int, col int) *Table

AddTable add a new table to body by col*row

unit: twips (1/20 point)

func (*Docx) AddTableTwips

func (f *Docx) AddTableTwips(rowHeights []int64, colWidths []int64) *Table

AddTableTwips add a new table to body by height and width

unit: twips (1/20 point)

func (*Docx) AppendFile

func (f *Docx) AppendFile(af *Docx)

AppendFile appends all contents in af to f

func (*Docx) IncreaseID

func (f *Docx) IncreaseID(name string) (n uintptr)

IncreaseID by name

func (*Docx) Media

func (f *Docx) Media(name string) *Media

Media get media struct pointer (or nil on notfound) by name

func (*Docx) RangeRelationships

func (f *Docx) RangeRelationships(iter func(*Relationship) error) error

RangeRelationships goes through each doc relation

func (*Docx) Read

func (f *Docx) Read(_ []byte) (int, error)

Read is a fake function and cannot be used

func (*Docx) ReferID

func (f *Docx) ReferID(target string) (string, error)

ReferID gets the rId from target

func (*Docx) ReferTarget

func (f *Docx) ReferTarget(id string) (string, error)

ReferTarget gets the target for a reference

func (*Docx) SplitByParagraph

func (f *Docx) SplitByParagraph(separator ParagraphSplitRule) (docs []*Docx)

SplitByParagraph splits a doc to many docs by using a matched paragraph as the separator.

The separator will be placed to the first doc item

func (*Docx) UseTemplate

func (f *Docx) UseTemplate(template string, tmpfslst []string, tmplfs fs.FS) *Docx

UseTemplate will replace template files

func (*Docx) WithA3Page

func (f *Docx) WithA3Page() *Docx

WithA3Page use A3 PageSize

func (*Docx) WithA4Page

func (f *Docx) WithA4Page() *Docx

WithA4Page use A4 PageSize

func (*Docx) WithDefaultTheme

func (f *Docx) WithDefaultTheme() *Docx

WithDefaultTheme use default theme embeded

func (*Docx) WriteTo

func (f *Docx) WriteTo(writer io.Writer) (_ int64, err error)

WriteTo allows to save a docx to a writer

type Drawing

type Drawing struct {
	XMLName xml.Name `xml:"w:drawing,omitempty"`
	Inline  *WPInline
	Anchor  *WPAnchor
	// contains filtered or unexported fields
}

Drawing element contains photos

func (*Drawing) UnmarshalXML

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

UnmarshalXML ...

type Highlight

type Highlight struct {
	XMLName xml.Name `xml:"w:highlight,omitempty"`
	Val     string   `xml:"w:val,attr,omitempty"`
}

Highlight ...

type Hyperlink struct {
	XMLName xml.Name `xml:"w:hyperlink,omitempty"`
	ID      string   `xml:"r:id,attr"`
	Run     Run
}

Hyperlink element contains links

func (*Hyperlink) UnmarshalXML

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

UnmarshalXML ...

type Ind

type Ind struct {
	XMLName xml.Name `xml:"w:ind,omitempty"`

	LeftChars      int `xml:"w:leftChars,attr,omitempty"`
	Left           int `xml:"w:left,attr,omitempty"`
	FirstLineChars int `xml:"w:firstLineChars,attr,omitempty"`
	FirstLine      int `xml:"w:firstLine,attr,omitempty"`
	HangingChars   int `xml:"w:hangingChars,attr,omitempty"`
	Hanging        int `xml:"w:hanging,attr,omitempty"`
}

Ind ...

func (*Ind) UnmarshalXML

func (i *Ind) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type Italic

type Italic struct {
	XMLName xml.Name `xml:"w:i,omitempty"`
}

Italic ...

type Justification

type Justification struct {
	XMLName xml.Name `xml:"w:jc,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

Justification contains the way of the horizonal alignment

w:jc 属性的取值可以是以下之一:
	start:左对齐。
	center:居中对齐。
	end:右对齐。
	both:两端对齐。
	distribute:分散对齐。

type Kern

type Kern struct {
	XMLName xml.Name `xml:"w:kern,omitempty"`
	Val     int64    `xml:"w:val,attr"`
}

Kern ...

type Kinsoku

type Kinsoku struct {
	XMLName xml.Name `xml:"w:kinsoku,omitempty"`
	Val     int      `xml:"w:val,attr"`
}

Kinsoku ...

type Media

type Media struct {
	Name string // Name is for word/media/Name
	Data []byte // Data is data of this media
}

Media is in word/media

func (*Media) String

func (m *Media) String() string

String is the full path of the media

type NonVisualProperties

type NonVisualProperties struct {
	ID   int    `xml:"id,attr"`
	Name string `xml:"name,attr"`
}

NonVisualProperties is an element that represents the non-visual properties of a content control.

func (*NonVisualProperties) UnmarshalXML

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

UnmarshalXML ...

type OverflowPunct

type OverflowPunct struct {
	XMLName xml.Name `xml:"w:overflowPunct,omitempty"`
	Val     int      `xml:"w:val,attr"`
}

OverflowPunct ...

type PICBlipFill

type PICBlipFill struct {
	XMLName xml.Name `xml:"pic:blipFill,omitempty"`
	Blip    ABlip
	Stretch AStretch
}

PICBlipFill represents the blip fill of a picture in a Word document.

func (*PICBlipFill) UnmarshalXML

func (p *PICBlipFill) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type PICNonVisualPicProperties

type PICNonVisualPicProperties struct {
	XMLName                    xml.Name            `xml:"pic:nvPicPr,omitempty"`
	NonVisualDrawingProperties NonVisualProperties `xml:"pic:cNvPr,omitempty"`
	CNvPicPr                   PicCNvPicPr
}

PICNonVisualPicProperties represents the non-visual properties of a picture in a Word document.

func (*PICNonVisualPicProperties) UnmarshalXML

func (p *PICNonVisualPicProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type PICSpPr

type PICSpPr struct {
	XMLName  xml.Name `xml:"pic:spPr,omitempty"`
	Xfrm     AXfrm
	PrstGeom *APrstGeom
}

PICSpPr is a struct representing the <pic:spPr> element in OpenXML, which describes the shape properties for a picture.

func (*PICSpPr) UnmarshalXML

func (p *PICSpPr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type Paragraph

type Paragraph struct {
	XMLName xml.Name `xml:"w:p,omitempty"`

	Properties *ParagraphProperties
	Children   []interface{}
	// contains filtered or unexported fields
}

Paragraph <w:p>

func (*Paragraph) AddAnchorDrawing

func (p *Paragraph) AddAnchorDrawing(pic []byte) (*Run, error)

AddAnchorDrawing adds inline drawing to paragraph

func (*Paragraph) AddAnchorDrawingFrom

func (p *Paragraph) AddAnchorDrawingFrom(file string) (*Run, error)

AddAnchorDrawingFrom adds drawing from file to paragraph

func (*Paragraph) AddAnchorShape

func (p *Paragraph) AddAnchorShape(w, h int64, name, bwMode, prst string, ln *ALine) *Run

AddAnchorShape adds wsp named drawing to paragraph

func (*Paragraph) AddInlineDrawing

func (p *Paragraph) AddInlineDrawing(pic []byte) (*Run, error)

AddInlineDrawing adds inline drawing to paragraph

func (*Paragraph) AddInlineDrawingFrom

func (p *Paragraph) AddInlineDrawingFrom(file string) (*Run, error)

AddInlineDrawingFrom adds drawing from file to paragraph

func (*Paragraph) AddInlineShape

func (p *Paragraph) AddInlineShape(w, h int64, name, bwMode, prst string, ln *ALine) *Run

AddInlineShape adds wsp named drawing to paragraph

func (p *Paragraph) AddLink(text string, link string) *Hyperlink

AddLink adds an hyperlink to paragraph

func (*Paragraph) AddPageBreaks

func (p *Paragraph) AddPageBreaks() *Run

AddPageBreaks adds a pagebreaks

func (*Paragraph) AddTab

func (p *Paragraph) AddTab() *Run

AddTab adds tab to para

func (*Paragraph) AddText

func (p *Paragraph) AddText(text string) *Run

AddText adds text to paragraph with \n

func (*Paragraph) DropCanvas

func (p *Paragraph) DropCanvas()

DropCanvas drops all canvases in paragraph

func (*Paragraph) DropGroup

func (p *Paragraph) DropGroup()

DropGroup drops all groups in paragraph

func (*Paragraph) DropNilPicture

func (p *Paragraph) DropNilPicture()

DropNilPicture drops all drawings with nil picture in paragraph

func (*Paragraph) DropShape

func (p *Paragraph) DropShape()

DropShape drops all shapes in paragraph

func (*Paragraph) DropShapeAndCanvas

func (p *Paragraph) DropShapeAndCanvas()

DropShapeAndCanvas drops all shapes and canvases in paragraph

func (*Paragraph) DropShapeAndCanvasAndGroup

func (p *Paragraph) DropShapeAndCanvasAndGroup()

DropShapeAndCanvasAndGroup drops all shapes, canvases and groups in paragraph

func (*Paragraph) Justification

func (p *Paragraph) Justification(val string) *Paragraph

Justification allows to set para's horizonal alignment

w:jc 属性的取值可以是以下之一:
	start:左对齐。
	center:居中对齐。
	end:右对齐。
	both:两端对齐。
	distribute:分散对齐。

func (*Paragraph) KeepElements

func (p *Paragraph) KeepElements(name ...string)

KeepElements keep named elems amd removes others

names: *docx.Hyperlink *docx.Run *docx.RunProperties

func (*Paragraph) MergeText

func (p *Paragraph) MergeText(canmerge RunMergeRule) (np Paragraph)

MergeText will merge contiguous run texts in a paragraph into one run

note: np is not a deep-copy

func (*Paragraph) String

func (p *Paragraph) String() string

func (*Paragraph) UnmarshalXML

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

UnmarshalXML ...

type ParagraphProperties

type ParagraphProperties struct {
	XMLName        xml.Name `xml:"w:pPr,omitempty"`
	Tabs           *Tabs
	Spacing        *Spacing
	Ind            *Ind
	Justification  *Justification
	Shade          *Shade
	Kern           *Kern
	Style          *Style
	TextAlignment  *TextAlignment
	AdjustRightInd *AdjustRightInd
	SnapToGrid     *SnapToGrid
	Kinsoku        *Kinsoku
	OverflowPunct  *OverflowPunct

	RunProperties *RunProperties
}

ParagraphProperties <w:pPr>

func (*ParagraphProperties) UnmarshalXML

func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type ParagraphSplitRule

type ParagraphSplitRule func(*Paragraph) bool

ParagraphSplitRule check whether the paragraph is a separator or not

func SplitDocxByPlainTextRegex

func SplitDocxByPlainTextRegex(re *regexp.Regexp) ParagraphSplitRule

SplitDocxByPlainTextRegex matches p.String()

type PgSz

type PgSz struct {
	W xml.Attr `xml:"w:w,attr"` // width of paper
	H xml.Attr `xml:"w:h,attr"` // high of paper
}

PgSz show the paper size

func (*PgSz) UnmarshalXML

func (pgsz *PgSz) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type PicCNvPicPr

type PicCNvPicPr struct {
	XMLName xml.Name `xml:"pic:cNvPicPr,omitempty"`
	Locks   *APicLocks
}

PicCNvPicPr represents the non-visual properties of a picture.

func (*PicCNvPicPr) UnmarshalXML

func (p *PicCNvPicPr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type Picture

type Picture struct {
	XMLName                xml.Name `xml:"pic:pic,omitempty"`
	XMLPIC                 string   `xml:"xmlns:pic,attr,omitempty"`
	NonVisualPicProperties *PICNonVisualPicProperties
	BlipFill               *PICBlipFill
	SpPr                   *PICSpPr
}

Picture represents a picture in a Word document.

func (*Picture) UnmarshalXML

func (p *Picture) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

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,omitempty"`
}

Relationship ...

type Relationships

type Relationships struct {
	Xmlns        string `xml:"xmlns,attr"`
	Relationship []Relationship
}

Relationships ...

type Run

type Run struct {
	XMLName xml.Name `xml:"w:r,omitempty"`
	Space   string   `xml:"xml:space,attr,omitempty"`

	RunProperties *RunProperties `xml:"w:rPr,omitempty"`

	InstrText string `xml:"w:instrText,omitempty"`

	Children []interface{}
	// contains filtered or unexported fields
}

Run is part of a paragraph that has its own style. It could be a piece of text in bold, or a link

func (*Run) AddTab

func (r *Run) AddTab() *Run

AddTab add a tab in front of the run

func (*Run) Bold

func (r *Run) Bold() *Run

Bold ...

func (*Run) Color

func (r *Run) Color(color string) *Run

Color allows to set run color

func (*Run) Font

func (r *Run) Font(ascii, hansi, hint string) *Run

Font sets the font of the run

func (*Run) Highlight

func (r *Run) Highlight(val string) *Run

Highlight ...

func (*Run) Italic

func (r *Run) Italic() *Run

Italic ...

func (*Run) KeepElements

func (r *Run) KeepElements(name ...string)

KeepElements keep named elems amd removes others

names: *docx.Text *docx.Drawing *docx.Tab *docx.BarterRabbet

func (*Run) Shade

func (r *Run) Shade(val, color, fill string) *Run

Shade allows to set run shade

func (*Run) Size

func (r *Run) Size(size string) *Run

Size allows to set run size

func (*Run) Underline

func (r *Run) Underline(val string) *Run

Underline has several possible values including

none: Specifies that no underline should be applied.
single: Specifies a single underline.
words: Specifies that only words within the text should be underlined.
double: Specifies a double underline.
thick: Specifies a thick underline.
dotted: Specifies a dotted underline.
dash: Specifies a dash underline.
dotDash: Specifies an alternating dot-dash underline.
dotDotDash: Specifies an alternating dot-dot-dash underline.
wave: Specifies a wavy underline.
dashLong: Specifies a long dash underline.
wavyDouble: Specifies a double wavy underline.

func (*Run) UnmarshalXML

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

UnmarshalXML ...

type RunFonts

type RunFonts struct {
	XMLName  xml.Name `xml:"w:rFonts,omitempty"`
	ASCII    string   `xml:"w:ascii,attr,omitempty"`
	EastAsia string   `xml:"w:eastAsia,attr,omitempty"`
	HAnsi    string   `xml:"w:hAnsi,attr,omitempty"`
	Hint     string   `xml:"w:hint,attr,omitempty"`
}

RunFonts specifies the fonts used in the text of a run.

func (*RunFonts) UnmarshalXML

func (f *RunFonts) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type RunMergeRule

type RunMergeRule func(r1, r2 *Run) bool

RunMergeRule compares two runs and decides whether they can be merged

func MergeSamePropRunsOf

func MergeSamePropRunsOf(name ...string) RunMergeRule

MergeSamePropRunsOf merges runs with the same properties of names

type RunProperties

type RunProperties struct {
	XMLName   xml.Name `xml:"w:rPr,omitempty"`
	Fonts     *RunFonts
	Bold      *Bold
	ICs       *struct{} `xml:"w:iCs,omitempty"`
	Italic    *Italic
	Highlight *Highlight
	Color     *Color
	Size      *Size
	SizeCs    *SizeCs
	Spacing   *Spacing
	RunStyle  *RunStyle
	Style     *Style
	Shade     *Shade
	Kern      *Kern
	Underline *Underline
	VertAlign *VertAlign
	Strike    *Strike
}

RunProperties encapsulates visual properties of a run

func (*RunProperties) UnmarshalXML

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

UnmarshalXML ...

type RunStyle

type RunStyle struct {
	XMLName xml.Name `xml:"w:rStyle,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

RunStyle contains styling for a run

type SectPr

type SectPr struct {
	XMLName xml.Name `xml:"w:sectPr,omitempty"` // properties of the document, including paper size
	PgSz    *PgSz    `xml:"w:pgSz,omitempty"`
}

SectPr show the properties of the document, like paper size

func (*SectPr) UnmarshalXML

func (sect *SectPr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type Shade

type Shade struct {
	XMLName       xml.Name `xml:"w:shd,omitempty"`
	Val           string   `xml:"w:val,attr,omitempty"`
	Color         string   `xml:"w:color,attr,omitempty"`
	Fill          string   `xml:"w:fill,attr,omitempty"`
	ThemeFill     string   `xml:"w:themeFill,attr,omitempty"`
	ThemeFillTint string   `xml:"w:themeFillTint,attr,omitempty"`
}

Shade is an element that represents a shading pattern applied to a document element.

func (*Shade) UnmarshalXML

func (s *Shade) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type ShapeProperties

type ShapeProperties struct {
	BWMode string `xml:"bwMode,attr"`

	Xfrm      AXfrm
	PrstGeom  APrstGeom
	SolidFill *ASolidFill
	BlipFill  *ABlipFill
	NoFill    *struct{} `xml:"a:noFill,omitempty"`
	Line      *ALine
}

ShapeProperties is a container element that represents the visual properties of a shape.

func (*ShapeProperties) UnmarshalXML

func (w *ShapeProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type Size

type Size struct {
	XMLName xml.Name `xml:"w:sz,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

Size contains the font size

type SizeCs

type SizeCs struct {
	XMLName xml.Name `xml:"w:szCs,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

SizeCs contains the cs font size

type SnapToGrid

type SnapToGrid struct {
	XMLName xml.Name `xml:"w:snapToGrid,omitempty"`
	Val     int      `xml:"w:val,attr"`
}

SnapToGrid ...

type Spacing

type Spacing struct {
	XMLName xml.Name `xml:"w:spacing,omitempty"`

	Val int `xml:"w:val,attr,omitempty"`

	BeforeLines int    `xml:"w:beforeLines,attr,omitempty"`
	Before      int    `xml:"w:before,attr,omitempty"`
	Line        int    `xml:"w:line,attr,omitempty"`
	LineRule    string `xml:"w:lineRule,attr,omitempty"`
}

Spacing ...

func (*Spacing) UnmarshalXML

func (s *Spacing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type Strike

type Strike struct {
	XMLName xml.Name `xml:"w:strike,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

Strike ...

type Style

type Style struct {
	XMLName xml.Name `xml:"w:pStyle,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

Style contains styling for a paragraph

type Tab

type Tab struct {
	XMLName  xml.Name `xml:"w:tab,omitempty"`
	Val      string   `xml:"w:val,attr,omitempty"`
	Position int      `xml:"w:pos,attr,omitempty"`
}

Tab is the literal tab

func (*Tab) UnmarshalXML

func (t *Tab) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type Table

type Table struct {
	XMLName         xml.Name `xml:"w:tbl,omitempty"`
	TableProperties *WTableProperties
	TableGrid       *WTableGrid
	TableRows       []*WTableRow
	// contains filtered or unexported fields
}

Table represents a table within a Word document.

func (*Table) Justification

func (t *Table) Justification(val string) *Table

Justification allows to set table's horizonal alignment

w:jc 属性的取值可以是以下之一:
	start:左对齐。
	center:居中对齐。
	end:右对齐。
	both:两端对齐。
	distribute:分散对齐。

func (*Table) String

func (t *Table) String() string

func (*Table) UnmarshalXML

func (t *Table) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type Tabs

type Tabs struct {
	XMLName xml.Name `xml:"w:tabs,omitempty"`
	Tabs    []*Tab
}

Tabs ...

func (*Tabs) UnmarshalXML

func (tb *Tabs) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type Text

type Text struct {
	XMLName xml.Name `xml:"w:t,omitempty"`

	XMLSpace string `xml:"xml:space,attr,omitempty"`

	Text string `xml:",chardata"`
}

Text object contains the actual text

func (*Text) UnmarshalXML

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

UnmarshalXML ...

type TextAlignment

type TextAlignment struct {
	XMLName xml.Name `xml:"w:textAlignment,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

TextAlignment ...

type Underline

type Underline struct {
	XMLName xml.Name `xml:"w:u,omitempty"`
	Val     string   `xml:"w:val,attr,omitempty"`
}

Underline ...

type VertAlign

type VertAlign struct {
	XMLName xml.Name `xml:"w:vertAlign,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

VertAlign ...

type WGridCol

type WGridCol struct {
	XMLName xml.Name `xml:"w:gridCol,omitempty"`
	W       int64    `xml:"w:w,attr"`
}

WGridCol is a structure that represents a table grid column of a Word document.

func (*WGridCol) UnmarshalXML

func (g *WGridCol) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type WGridSpan

type WGridSpan struct {
	XMLName xml.Name `xml:"w:gridSpan,omitempty"`
	Val     int      `xml:"w:val,attr"`
}

WGridSpan represents the number of grid columns this cell should span.

type WPAnchor

type WPAnchor struct {
	XMLName        xml.Name `xml:"wp:anchor,omitempty"`
	DistT          int64    `xml:"distT,attr"`
	DistB          int64    `xml:"distB,attr"`
	DistL          int64    `xml:"distL,attr"`
	DistR          int64    `xml:"distR,attr"`
	SimplePos      int      `xml:"simplePos,attr"`
	RelativeHeight int      `xml:"relativeHeight,attr"`
	BehindDoc      int      `xml:"behindDoc,attr"`
	Locked         int      `xml:"locked,attr"`
	LayoutInCell   int      `xml:"layoutInCell,attr"`
	AllowOverlap   int      `xml:"allowOverlap,attr"`

	SimplePosXY       *WPSimplePos
	PositionH         *WPPositionH
	PositionV         *WPPositionV
	Extent            *WPExtent
	EffectExtent      *WPEffectExtent
	WrapNone          *struct{} `xml:"wp:wrapNone,omitempty"`
	WrapSquare        *WPWrapSquare
	DocPr             *WPDocPr
	CNvGraphicFramePr *WPCNvGraphicFramePr
	Graphic           *AGraphic
	// contains filtered or unexported fields
}

WPAnchor is an element that represents an anchored object in a Word document.

It allows for the positioning of a drawing object relative to a specific location in the text of the document. The <wp:anchor> element contains child elements that specify the dimensions and position of the anchored object, as well as the non-visual properties of the object. The <wp:anchor> element can contain the <wp:docPr> element, which contains the non-visual properties of the anchored object, such as its ID and name, as well as the <a:graphic> element, which specifies the visual properties of the object, such as its shape and fill.

func (*WPAnchor) Size

func (r *WPAnchor) Size(w, h int64)

Size of the anchor drawing by EMU

func (*WPAnchor) String

func (r *WPAnchor) String() string

String ...

func (*WPAnchor) UnmarshalXML

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

UnmarshalXML ...

type WPCBackground

type WPCBackground struct {
	XMLName xml.Name  `xml:"wpc:bg,omitempty"`
	NoFill  *struct{} `xml:"a:noFill,omitempty"`
}

WPCBackground ...

func (*WPCBackground) UnmarshalXML

func (b *WPCBackground) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) (err error)

UnmarshalXML ...

type WPCNvGraphicFramePr

type WPCNvGraphicFramePr struct {
	XMLName xml.Name `xml:"wp:cNvGraphicFramePr,omitempty"`
	Locks   AGraphicFrameLocks
}

WPCNvGraphicFramePr represents the non-visual properties of a graphic frame.

func (*WPCNvGraphicFramePr) UnmarshalXML

func (w *WPCNvGraphicFramePr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WPCWhole

type WPCWhole struct {
	XMLName xml.Name `xml:"wpc:whole,omitempty"`
	Line    *ALine
}

WPCWhole ...

func (*WPCWhole) UnmarshalXML

func (w *WPCWhole) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) (err error)

UnmarshalXML ...

type WPDocPr

type WPDocPr struct {
	XMLName xml.Name `xml:"wp:docPr,omitempty"`
	ID      int      `xml:"id,attr"`
	Name    string   `xml:"name,attr,omitempty"`
}

WPDocPr represents the document properties of a drawing in a Word document.

func (*WPDocPr) UnmarshalXML

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

UnmarshalXML ...

type WPEffectExtent

type WPEffectExtent struct {
	XMLName xml.Name `xml:"wp:effectExtent,omitempty"`
	L       int64    `xml:"l,attr"`
	T       int64    `xml:"t,attr"`
	R       int64    `xml:"r,attr"`
	B       int64    `xml:"b,attr"`
}

WPEffectExtent represents the effect extent of a drawing in a Word document.

func (*WPEffectExtent) UnmarshalXML

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

UnmarshalXML ...

type WPExtent

type WPExtent struct {
	XMLName xml.Name `xml:"wp:extent,omitempty"`
	CX      int64    `xml:"cx,attr"`
	CY      int64    `xml:"cy,attr"`
}

WPExtent represents the extent of a drawing in a Word document.

CX CY 's unit is English Metric Units, which is 1/914400 inch

func (*WPExtent) UnmarshalXML

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

UnmarshalXML ...

type WPGGroupShape

type WPGGroupShape struct {
	XMLName              xml.Name             `xml:"wpg:grpSp,omitempty"`
	CNvPr                *NonVisualProperties `xml:"wpg:cNvPr,omitempty"`
	CNvGrpSpPr           *WPGcNvGrpSpPr
	GroupShapeProperties *ShapeProperties `xml:"wpg:grpSpPr,omitempty"`
	Elems                []interface{}
	// contains filtered or unexported fields
}

WPGGroupShape ...

func (*WPGGroupShape) UnmarshalXML

func (w *WPGGroupShape) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WPGcNvGrpSpPr

type WPGcNvGrpSpPr struct {
	XMLName xml.Name `xml:"wpg:cNvGrpSpPr,omitempty"`
	Locks   *AGroupShapeLocks
}

WPGcNvGrpSpPr represents the non-visual properties of a group shape.

func (*WPGcNvGrpSpPr) UnmarshalXML

func (w *WPGcNvGrpSpPr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WPInline

type WPInline struct {
	XMLName xml.Name `xml:"wp:inline,omitempty"`
	DistT   int64    `xml:"distT,attr"`
	DistB   int64    `xml:"distB,attr"`
	DistL   int64    `xml:"distL,attr"`
	DistR   int64    `xml:"distR,attr"`

	Extent            *WPExtent
	EffectExtent      *WPEffectExtent
	DocPr             *WPDocPr
	CNvGraphicFramePr *WPCNvGraphicFramePr
	Graphic           *AGraphic
	// contains filtered or unexported fields
}

WPInline is an element that represents an inline image within a text paragraph.

It contains information about the image's size and position, as well as any non-visual properties associated with the image. The <wp:inline> element can contain child elements such as <wp:extent> to specify the dimensions of the image and <wp:cNvGraphicFramePr> to specify the non-visual properties of the image. Inline images are often used in documents where the images are meant to be treated as part of the text flow, such as in a newsletter or a product brochure.

func (*WPInline) Size

func (r *WPInline) Size(w, h int64)

Size of the inline drawing by EMU

func (*WPInline) String

func (r *WPInline) String() string

String ...

func (*WPInline) UnmarshalXML

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

UnmarshalXML ...

type WPPositionH

type WPPositionH struct {
	XMLName      xml.Name `xml:"wp:positionH,omitempty"`
	RelativeFrom string   `xml:"relativeFrom,attr"`
	PosOffset    int64    `xml:"wp:posOffset"`
}

WPPositionH represents the horizontal position of an object in a Word document.

func (*WPPositionH) UnmarshalXML

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

UnmarshalXML ...

type WPPositionV

type WPPositionV struct {
	XMLName      xml.Name `xml:"wp:positionV,omitempty"`
	RelativeFrom string   `xml:"relativeFrom,attr"`
	PosOffset    int64    `xml:"wp:posOffset"`
}

WPPositionV represents the vertical position of an object in a Word document.

func (*WPPositionV) UnmarshalXML

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

UnmarshalXML ...

type WPSBodyPr

type WPSBodyPr struct {
	XMLName   xml.Name `xml:"wps:bodyPr,omitempty"`
	Rot       int      `xml:"rot,attr"`
	Vert      string   `xml:"vert,attr,omitempty"`
	Wrap      string   `xml:"wrap,attr,omitempty"`
	LIns      int64    `xml:"lIns,attr"`
	TIns      int64    `xml:"tIns,attr"`
	RIns      int64    `xml:"rIns,attr"`
	BIns      int64    `xml:"bIns,attr"`
	Anchor    string   `xml:"anchor,attr,omitempty"`
	AnchorCtr int      `xml:"anchorCtr,attr"`
	Upright   int      `xml:"upright,attr"`

	NoAutofit *struct{} `xml:"a:noAutofit,omitempty"`
}

WPSBodyPr represents the body properties for a WordprocessingML DrawingML shape.

func (*WPSBodyPr) UnmarshalXML

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

UnmarshalXML ...

type WPSCNvCnPr

type WPSCNvCnPr struct {
	XMLName        xml.Name  `xml:"wps:cNvCnPr,omitempty"`
	ConnShapeLocks *struct{} `xml:"a:cxnSpLocks,omitempty"`
}

WPSCNvCnPr represents the non-visual drawing properties of a connector.

func (*WPSCNvCnPr) UnmarshalXML

func (w *WPSCNvCnPr) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WPSCNvSpPr

type WPSCNvSpPr struct {
	XMLName xml.Name `xml:"wps:cNvSpPr,omitempty"`
	TxBox   int      `xml:"txBox,attr,omitempty"`

	SPLocks *ASPLocks
}

WPSCNvSpPr represents the non-visual properties of a WordArt object.

func (*WPSCNvSpPr) UnmarshalXML

func (w *WPSCNvSpPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type WPSTextBox

type WPSTextBox struct {
	XMLName xml.Name `xml:"wps:txbx,omitempty"`
	Content *WTextBoxContent
	// contains filtered or unexported fields
}

WPSTextBox ...

func (*WPSTextBox) UnmarshalXML

func (b *WPSTextBox) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WPSimplePos

type WPSimplePos struct {
	XMLName xml.Name `xml:"wp:simplePos,omitempty"`
	X       int64    `xml:"x,attr"`
	Y       int64    `xml:"y,attr"`
}

WPSimplePos represents the position of an object in a Word document.

type WPWrapSquare

type WPWrapSquare struct {
	XMLName  xml.Name `xml:"wp:wrapSquare,omitempty"`
	WrapText string   `xml:"wrapText,attr"`
}

WPWrapSquare represents the square wrapping of an object in a Word document.

type WTableBorder

type WTableBorder struct {
	Val   string `xml:"w:val,attr,omitempty"`
	Size  int    `xml:"w:sz,attr,omitempty"`
	Space int    `xml:"w:space,attr,omitempty"`
	Color string `xml:"w:color,attr,omitempty"`
}

WTableBorder is a structure representing a single border of a Word table.

func (*WTableBorder) UnmarshalXML

func (t *WTableBorder) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type WTableBorders

type WTableBorders struct {
	Top     *WTableBorder `xml:"w:top,omitempty"`
	Left    *WTableBorder `xml:"w:left,omitempty"`
	Bottom  *WTableBorder `xml:"w:bottom,omitempty"`
	Right   *WTableBorder `xml:"w:right,omitempty"`
	InsideH *WTableBorder `xml:"w:insideH,omitempty"`
	InsideV *WTableBorder `xml:"w:insideV,omitempty"`
}

WTableBorders is a structure representing the borders of a Word table.

func (*WTableBorders) UnmarshalXML

func (w *WTableBorders) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WTableCell

type WTableCell struct {
	XMLName             xml.Name `xml:"w:tc,omitempty"`
	TableCellProperties *WTableCellProperties
	Paragraphs          []*Paragraph `xml:"w:p,omitempty"`
	// contains filtered or unexported fields
}

WTableCell represents a cell within a table.

func (*WTableCell) AddParagraph

func (c *WTableCell) AddParagraph() *Paragraph

AddParagraph adds a new paragraph

func (*WTableCell) Shade

func (c *WTableCell) Shade(val, color, fill string) *WTableCell

Shade allows to set cell's shade

func (*WTableCell) UnmarshalXML

func (c *WTableCell) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WTableCellProperties

type WTableCellProperties struct {
	XMLName        xml.Name `xml:"w:tcPr,omitempty"`
	TableCellWidth *WTableCellWidth
	VMerge         *WvMerge
	GridSpan       *WGridSpan
	TableBorders   *WTableBorders `xml:"w:tcBorders"`
	Shade          *Shade
	VAlign         *WVerticalAlignment
}

WTableCellProperties represents the properties of a table cell.

func (*WTableCellProperties) UnmarshalXML

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

UnmarshalXML ...

type WTableCellWidth

type WTableCellWidth struct {
	XMLName xml.Name `xml:"w:tcW,omitempty"`
	W       int64    `xml:"w:w,attr"`
	Type    string   `xml:"w:type,attr"`
}

WTableCellWidth represents the width of a table cell.

在w:tcW元素中,type属性可以有以下几种取值:

"auto":表示表格列宽度由文本或表格布局决定。
"dxa":表示表格列宽度使用磅为单位。

不同的取值对应着不同的宽度计量单位和宽度定义方式。

type WTableGrid

type WTableGrid struct {
	XMLName  xml.Name    `xml:"w:tblGrid,omitempty"`
	GridCols []*WGridCol `xml:"w:gridCol,omitempty"`
}

WTableGrid is a structure that represents the table grid of a Word document.

func (*WTableGrid) UnmarshalXML

func (t *WTableGrid) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WTableLook

type WTableLook struct {
	XMLName  xml.Name `xml:"w:tblLook,omitempty"`
	Val      string   `xml:"w:val,attr"`
	FirstRow int      `xml:"w:firstRow,attr"`
	LastRow  int      `xml:"w:lastRow,attr"`
	FirstCol int      `xml:"w:firstColumn,attr"`
	LastCol  int      `xml:"w:lastColumn,attr"`
	NoHBand  int      `xml:"w:noHBand,attr"`
	NoVBand  int      `xml:"w:noVBand,attr"`
}

WTableLook represents the look of a table in a Word document.

func (*WTableLook) UnmarshalXML

func (t *WTableLook) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type WTablePositioningProperties

type WTablePositioningProperties struct {
	XMLName       xml.Name `xml:"w:tblpPr,omitempty"`
	LeftFromText  int      `xml:"w:leftFromText,attr,omitempty"`
	RightFromText int      `xml:"w:rightFromText,attr,omitempty"`
	VertAnchor    string   `xml:"w:vertAnchor,attr,omitempty"`
	HorzAnchor    string   `xml:"w:horzAnchor,attr,omitempty"`
	TblpXSpec     string   `xml:"w:tblpXSpec,attr,omitempty"`
	TblpYSpec     string   `xml:"w:tblpYSpec,attr,omitempty"`
	TblpX         int      `xml:"w:tblpX,attr,omitempty"`
	TblpY         int      `xml:"w:tblpY,attr,omitempty"`
}

WTablePositioningProperties is an element that contains the properties for positioning a table within a document page, including its horizontal and vertical anchors, distance from text, and coordinates.

func (*WTablePositioningProperties) UnmarshalXML

func (tp *WTablePositioningProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type WTableProperties

type WTableProperties struct {
	XMLName       xml.Name `xml:"w:tblPr,omitempty"`
	Position      *WTablePositioningProperties
	Style         *WTableStyle
	Width         *WTableWidth
	Justification *Justification `xml:"w:jc,omitempty"`
	TableBorders  *WTableBorders `xml:"w:tblBorders"`
	Look          *WTableLook
}

WTableProperties is an element that represents the properties of a table in Word document.

func (*WTableProperties) UnmarshalXML

func (t *WTableProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

type WTableRow

type WTableRow struct {
	XMLName xml.Name `xml:"w:tr,omitempty"`
	// RsidR              string   `xml:"w:rsidR,attr,omitempty"`
	// RsidRPr            string   `xml:"w:rsidRPr,attr,omitempty"`
	// RsidTr             string   `xml:"w:rsidTr,attr,omitempty"`
	TableRowProperties *WTableRowProperties
	TableCells         []*WTableCell
	// contains filtered or unexported fields
}

WTableRow represents a row within a table.

func (*WTableRow) Justification

func (w *WTableRow) Justification(val string) *WTableRow

Justification allows to set table's horizonal alignment

w:jc 属性的取值可以是以下之一:
	start:左对齐。
	center:居中对齐。
	end:右对齐。
	both:两端对齐。
	distribute:分散对齐。

func (*WTableRow) UnmarshalXML

func (w *WTableRow) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WTableRowHeight

type WTableRowHeight struct {
	XMLName xml.Name `xml:"w:trHeight,omitempty"`
	Rule    string   `xml:"w:hRule,attr,omitempty"`
	Val     int64    `xml:"w:val,attr"`
}

WTableRowHeight represents the height of a row within a table.

type WTableRowProperties

type WTableRowProperties struct {
	XMLName        xml.Name `xml:"w:trPr,omitempty"`
	TableRowHeight *WTableRowHeight
	Justification  *Justification
}

WTableRowProperties represents the properties of a row within a table.

func (*WTableRowProperties) UnmarshalXML

func (t *WTableRowProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WTableStyle

type WTableStyle struct {
	XMLName xml.Name `xml:"w:tblStyle,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

WTableStyle represents the style of a table in a Word document.

func (*WTableStyle) UnmarshalXML

func (t *WTableStyle) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type WTableWidth

type WTableWidth struct {
	XMLName xml.Name `xml:"w:tblW,omitempty"`
	W       int64    `xml:"w:w,attr"`
	Type    string   `xml:"w:type,attr"`
}

WTableWidth represents the width of a table in a Word document.

func (*WTableWidth) UnmarshalXML

func (t *WTableWidth) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML ...

type WTextBoxContent

type WTextBoxContent struct {
	XMLName    xml.Name    `xml:"w:txbxContent,omitempty"`
	Paragraphs []Paragraph `xml:"w:p,omitempty"`
	// contains filtered or unexported fields
}

WTextBoxContent ...

func (*WTextBoxContent) UnmarshalXML

func (c *WTextBoxContent) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WVerticalAlignment

type WVerticalAlignment struct {
	XMLName xml.Name `xml:"w:vAlign,omitempty"`
	Val     string   `xml:"w:val,attr"`
}

WVerticalAlignment represents the vertical alignment of the content of a cell.

type WordprocessingCanvas

type WordprocessingCanvas struct {
	XMLName    xml.Name `xml:"wpc:wpc,omitempty"`
	Background *WPCBackground
	Whole      *WPCWhole

	Items []interface{}
	// contains filtered or unexported fields
}

WordprocessingCanvas ...

func (*WordprocessingCanvas) UnmarshalXML

func (c *WordprocessingCanvas) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) (err error)

UnmarshalXML ...

type WordprocessingGroup

type WordprocessingGroup struct {
	XMLName              xml.Name `xml:"wpg:wgp,omitempty"`
	CNvGrpSpPr           *WPGcNvGrpSpPr
	GroupShapeProperties *ShapeProperties `xml:"wpg:grpSpPr,omitempty"`
	Elems                []interface{}
	// contains filtered or unexported fields
}

WordprocessingGroup represents a group of drawing objects or pictures

func (*WordprocessingGroup) UnmarshalXML

func (w *WordprocessingGroup) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WordprocessingShape

type WordprocessingShape struct {
	XMLName xml.Name             `xml:"wps:wsp,omitempty"`
	CNvPr   *NonVisualProperties `xml:"wps:cNvPr,omitempty"`
	CNvCnPr *WPSCNvCnPr
	CNvSpPr *WPSCNvSpPr
	SpPr    *ShapeProperties `xml:"wps:spPr,omitempty"`
	TextBox *WPSTextBox
	BodyPr  *WPSBodyPr
	// contains filtered or unexported fields
}

WordprocessingShape is a container for a WordprocessingML DrawingML shape.

func (*WordprocessingShape) UnmarshalXML

func (w *WordprocessingShape) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML ...

type WvMerge

type WvMerge struct {
	XMLName xml.Name `xml:"w:vMerge,omitempty"`
	Val     string   `xml:"w:val,attr,omitempty"`
}

WvMerge element is used to specify whether a table cell should be vertically merged with the cell(s) above or below it. When a cell is merged, its content is merged as well.

The <w:vMerge> element has a single attribute called val which specifies the merge behavior. Its possible values are:

continue: This value indicates that the current cell is part
of a vertically merged group of cells, but it is not the first cell
in that group. It means that the current cell should not have its
own content and should inherit the content of the first cell in the merged group.

restart: This value indicates that the current cell is the first cell in a
new vertically merged group of cells. It means that the current cell should
have its own content and should be used as the topmost cell in the merged group.

Note that the <w:vMerge> element is only used in table cells that are part of a vertically merged group. For cells that are not part of a merged group, this element should be omitted.

Directories

Path Synopsis
cmd
main
Package main is a function demo
Package main is a function demo

Jump to

Keyboard shortcuts

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