From 4f44062fe166e27935bb8cf30d20e89a4f112616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 2 Mar 2023 20:05:09 +0800 Subject: [PATCH] add f.UseTemplate --- docx.go | 7 +++++++ empty.go | 12 ++---------- fs.go | 11 +++++++++++ structshape.go | 4 ++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docx.go b/docx.go index 3e7dbe2..43501cd 100644 --- a/docx.go +++ b/docx.go @@ -124,3 +124,10 @@ func (f *Docx) Read(p []byte) (n int, err error) { f.isbufempty = false return f.buf.Read(p) } + +// UseTemplate will replace template files +func (f *Docx) UseTemplate(template string, tmpfslst []string, tmplfs fs.FS) { + f.template = template + f.tmplfs = tmplfs + f.tmpfslst = tmpfslst +} diff --git a/empty.go b/empty.go index 6f7451f..e3735cb 100644 --- a/empty.go +++ b/empty.go @@ -67,16 +67,8 @@ func newEmptyA4File() *Docx { rID: 3, slowIDs: make(map[string]uintptr, 64), template: "a4", - tmpfslst: []string{ - "_rels/.rels", - "docProps/app.xml", - "docProps/core.xml", - "word/theme/theme1.xml", - "word/fontTable.xml", - "word/styles.xml", - "[Content_Types].xml", - }, - buf: bytes.NewBuffer(make([]byte, 0, 1024*1024)), + tmpfslst: A4TemplateFilesList, + buf: bytes.NewBuffer(make([]byte, 0, 1024*1024)), } docx.Document.Body.file = docx return docx diff --git a/fs.go b/fs.go index bfbf6a2..ecc953f 100644 --- a/fs.go +++ b/fs.go @@ -27,4 +27,15 @@ var ( //go:embed xml //go:embed xml/a4/_rels/* TemplateXMLFS embed.FS + + // A4TemplateFileList is the files list under TemplateXMLFS/xml/a4 + A4TemplateFilesList = []string{ + "_rels/.rels", + "docProps/app.xml", + "docProps/core.xml", + "word/theme/theme1.xml", + "word/fontTable.xml", + "word/styles.xml", + "[Content_Types].xml", + } ) diff --git a/structshape.go b/structshape.go index 72329ae..8e4c7a5 100644 --- a/structshape.go +++ b/structshape.go @@ -230,8 +230,8 @@ type WPSSpPr struct { NoFill *struct{} `xml:"a:noFill,omitempty"` Line *ALine - EffectList struct{} `xml:"a:effectLst"` - ExtList struct{} `xml:"a:extLst"` + // EffectList struct{} `xml:"a:effectLst"` + // ExtList struct{} `xml:"a:extLst"` } // UnmarshalXML ...