docxlib

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2022 License: MIT Imports: 20 Imported by: 0

README

docxlib

golang操作docx word 文档

Documentation

Index

Constants

View Source
const (
	LEFT  = "left"
	RIGHt = "right"
)

Variables

View Source
var (
	UNIT = [5]string{"", "十", "百", "千", "万"}
	NUM  = [10]string{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
)
View Source
var TEMP_BASE_DIR = path.Join("/tmp", "/docx_temp")

Functions

func CopyFile

func CopyFile(dstFileName string, srcFileName string) (written int64, err error)

func GenerateFileName

func GenerateFileName(fName, suffix string, replace bool) (tempName string)

func GenerateId

func GenerateId(sid, suffix, separation string) (toId string)

func GetBreakPage

func GetBreakPage() (tag *yaxml.Element)

func GetChunkContenDom

func GetChunkContenDom(filename string) (dom *yaxml.Element)

func GetChunkDom

func GetChunkDom(rid string) (dom *yaxml.Element)

func GetChunkRelationDom

func GetChunkRelationDom(filename, rid string) (dom *yaxml.Element)

func GetImageDom

func GetImageDom(rid string, width int, height int, align string) (dom *yaxml.Element)

func GetImageRelationshipDom

func GetImageRelationshipDom(rid, filename string) (dom *yaxml.Element)

func GetJpgContenttype

func GetJpgContenttype() (dom *yaxml.Element)

func GetPngContenttype

func GetPngContenttype() (dom *yaxml.Element)

func GetTextDom

func GetTextDom(text, align string) (dom *yaxml.Element)

func MergeFiles

func MergeFiles(filelist []string, filename string, page bool) (err error)

func NumToHans

func NumToHans(num int) string

�数字转汉字

func Parser

func Parser(text string) *yaxml.Element

func PathExists

func PathExists(path string) (bool, error)

func ReadAll

func ReadAll(filePth string) (string, error)

func Unzip

func Unzip(zipFile string, destDir string) error

Types

type ContentTypes

type ContentTypes struct {
	Content   *yaxml.Element
	Types     []string
	Extension map[string]bool
}

func GenerateContentTypes

func GenerateContentTypes(content *yaxml.Element) (ct *ContentTypes)

func (*ContentTypes) AppendDocx

func (c *ContentTypes) AppendDocx(filename string)

func (*ContentTypes) AppendExtension

func (c *ContentTypes) AppendExtension(suffix string)

func (*ContentTypes) AppendJpeg

func (c *ContentTypes) AppendJpeg()

func (*ContentTypes) AppendPng

func (c *ContentTypes) AppendPng()

func (*ContentTypes) GetDom

func (c *ContentTypes) GetDom() *yaxml.Element

func (*ContentTypes) GetTypes

func (c *ContentTypes) GetTypes() []string

func (*ContentTypes) GetTypesDom

func (c *ContentTypes) GetTypesDom() (types []*yaxml.Element)

func (*ContentTypes) ToString

func (c *ContentTypes) ToString() string

type Document

type Document struct {
	Docu *yaxml.Element
}

func GenerateDocument

func GenerateDocument(document *yaxml.Element) *Document

func (*Document) AppendChunk

func (d *Document) AppendChunk(rid string)

func (*Document) AppendContent

func (d *Document) AppendContent(dom *yaxml.Element)

func (*Document) AppendPageBreak

func (d *Document) AppendPageBreak()

func (*Document) AppendParagraph

func (d *Document) AppendParagraph(text string, align string)

func (*Document) AppendPicture

func (d *Document) AppendPicture(rid string, width int, height int, align string)

func (*Document) ClearContent

func (d *Document) ClearContent()

func (*Document) ClearContentWithoutHeader

func (d *Document) ClearContentWithoutHeader()

func (*Document) GetContent

func (d *Document) GetContent() (par []*Paragraph)

func (*Document) GetDom

func (d *Document) GetDom(dom *yaxml.Element) *yaxml.Element

func (*Document) ToString

func (d *Document) ToString() string

type Docx

type Docx struct {
	*IdAble
	Document        *Document
	ContentTypes    *ContentTypes
	Relationships   *Relationships
	Numbering       string
	Styles          string
	BaseDir         string
	FilePath        string
	ReplaceMap      map[string]string
	RelsDict        map[string]string
	RelsFiles       map[string]bool
	CurrentIdTarget map[string]bool
}

func MakeNewDocument

func MakeNewDocument() (doc *Docx, err error)

func NewDocx

func NewDocx(zipPath string, clearContent bool) (docx *Docx, err error)

func (*Docx) AppendParagraph

func (d *Docx) AppendParagraph(text, align string)

func (*Docx) AppendPicture

func (d *Docx) AppendPicture(srcfilepath, align string) (err error)

func (*Docx) Close

func (d *Docx) Close()

func (*Docx) GetDocument

func (d *Docx) GetDocument() (*Document, error)

func (*Docx) GetRelationships

func (d *Docx) GetRelationships(refresh bool) (*Relationships, error)

func (*Docx) Merge

func (d *Docx) Merge(filelist []string, page bool, remove bool) (err error)

func (*Docx) Replace

func (d *Docx) Replace(src, des string)

func (*Docx) Save

func (d *Docx) Save(name string) (err error)

func (*Docx) Zip

func (d *Docx) Zip(destZip string) error

srcFile could be a single file or a directory

type IdAble

type IdAble struct {
	Id   string
	Num  int
	Part int
}

func GenerateIdAble

func GenerateIdAble() (ia *IdAble, err error)

func (*IdAble) GetIdAndInc

func (id *IdAble) GetIdAndInc() int

type Paragraph

type Paragraph struct {
	Dom *yaxml.Element
}

func GenerateParagraph

func GenerateParagraph(dom *yaxml.Element) *Paragraph

func (*Paragraph) GetContent

func (p *Paragraph) GetContent() (text []string)

func (*Paragraph) GetDom

func (p *Paragraph) GetDom() *yaxml.Element

type Relationships

type Relationships struct {
	Relation    *yaxml.Element
	FileMapping map[string]string
	StartId     int
}

func GenerateRelationships

func GenerateRelationships(relationships *yaxml.Element) *Relationships

func (*Relationships) AppendChunk

func (r *Relationships) AppendChunk(filename string) string

func (*Relationships) AppendRelationship

func (r *Relationships) AppendRelationship(suffix string) (res map[string]string)

func (*Relationships) GenerateId

func (r *Relationships) GenerateId() string

func (*Relationships) GetDom

func (r *Relationships) GetDom() (dom *yaxml.Element)

func (*Relationships) GetFileMapping

func (r *Relationships) GetFileMapping() map[string]string

func (*Relationships) GetRelationships

func (r *Relationships) GetRelationships() (ralation []*yaxml.Element)

func (*Relationships) ToString

func (r *Relationships) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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