Closed timohahaa closed 9 months ago
Actually, it is not an issue caused by this lib but some common programming sense. But well, I would not refuse to offer some help. You cannot just write something back to the original file because docx file is actually a zip
. It will ignore what you had appended/overlapped after the package. What you should do is moving the file I/O
out of your block and use os.Create
to create a new file to write to.
You can refer to this minimized code:
f, err := os.Create(name)
if err != nil {
panic(err)
}
newFile := docx.NewA4()
// your loop
for i := 0; i < 10; i++ {
newFile.AppendFile(doc)
}
// write it at last, only once
_, err = io.Copy(f, newFile)
if err != nil {
panic(err)
}
Hello! I'll try my best to make this issue the last one, so I won't litter issues with my questions that much. Thanks for the help in advance!!! code:
this whole block of code is executed about 3-4 times, and should add one line to the file at a time however, after the program exits, the created file has only one out of 3-4 lines it should I tried literally everything at this point, but still cant get it to work...