1 year ago
#360652
ABDULLOKH MUKHAMMADJONOV
insert image into a specific place of docx file using golang
I am trying to fill a docx template dynamically using the golang package "github.com/lukasjarosch/go-docx"
.
I can replace all the text fields accordingly with this code:
package main
import (
docx "github.com/lukasjarosch/go-docx"
)
func main() {
// some logic here
replaceMap := docx.PlaceholderMap{
"personName": name,
"companyName": company_name,
"cityName": city_name,
// .....
}
// read and parse the template docx
doc, err := docx.Open("rental_contract_template.docx")
if err != nil {
panic(err)
}
// replace the keys with values from replaceMap
err = doc.ReplaceAll(replaceMap)
if err != nil {
panic(err)
}
// write out a new file
err = doc.WriteToFile("replaced.docx")
if err != nil {
panic(err)
}
}
Now I want to insert an image at {QRODE}
. I found out that unfortunately, this package does not provide this functionality. I am lacking the knowledge to work with XML
directly. I am supposed to not use "github.com/unidoc/unioffice"
.
How can I insert an image at that specific place?
go
docx
0 Answers
Your Answer