1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-13 04:13:15 +08:00

add f.UseTemplate

This commit is contained in:
源文雨
2023-03-02 20:05:09 +08:00
parent 8b3cf0260d
commit 4f44062fe1
4 changed files with 22 additions and 12 deletions

View File

@@ -124,3 +124,10 @@ func (f *Docx) Read(p []byte) (n int, err error) {
f.isbufempty = false f.isbufempty = false
return f.buf.Read(p) 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
}

View File

@@ -67,16 +67,8 @@ func newEmptyA4File() *Docx {
rID: 3, rID: 3,
slowIDs: make(map[string]uintptr, 64), slowIDs: make(map[string]uintptr, 64),
template: "a4", template: "a4",
tmpfslst: []string{ tmpfslst: A4TemplateFilesList,
"_rels/.rels", buf: bytes.NewBuffer(make([]byte, 0, 1024*1024)),
"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)),
} }
docx.Document.Body.file = docx docx.Document.Body.file = docx
return docx return docx

11
fs.go
View File

@@ -27,4 +27,15 @@ var (
//go:embed xml //go:embed xml
//go:embed xml/a4/_rels/* //go:embed xml/a4/_rels/*
TemplateXMLFS embed.FS 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",
}
) )

View File

@@ -230,8 +230,8 @@ type WPSSpPr struct {
NoFill *struct{} `xml:"a:noFill,omitempty"` NoFill *struct{} `xml:"a:noFill,omitempty"`
Line *ALine Line *ALine
EffectList struct{} `xml:"a:effectLst"` // EffectList struct{} `xml:"a:effectLst"`
ExtList struct{} `xml:"a:extLst"` // ExtList struct{} `xml:"a:extLst"`
} }
// UnmarshalXML ... // UnmarshalXML ...