Skip to content

.docx get corrupted after writing file #26

@cyberpunx

Description

@cyberpunx

I'm not sure of what's happening here. I have a perfectly functioning .docx as input file. But after parse it (didn't mody a thing) and write it as new file.. the output file gets corrupted)

func OpenDocx(path string) *docx.Docx {
	readFile, err := os.Open(path)
	util.Panic(err)
	fileInfo, err := readFile.Stat()
	util.Panic(err)
	size := fileInfo.Size()
	doc, err := docx.Parse(readFile, size)
	util.Panic(err)
	return doc
}

func WriteDocx(doc *docx.Docx, path string) {
	f, err := os.Create(path)
	util.Panic(err)
	_, err = doc.WriteTo(f)
	util.Panic(err)
	err = f.Close()
	util.Panic(err)
}

and somwhere in my main.go

...
...
doc := docxLib.OpenDocx(inputFile)
docxLib.WriteDocx(doc, "copy.docx")
...
...

when I try to open copy.docx in Word, I cannot because of corrupted file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions