unidoc / unioffice

Pure go library for creating and processing Office Word (.docx), Excel (.xlsx) and Powerpoint (.pptx) documents
https://unidoc.io/unioffice/
Other
4.35k stars 469 forks source link

How to save as Word Document #372

Closed EP-Toushirou closed 4 years ago

EP-Toushirou commented 4 years ago

Description

Hello, could you please tell me how can I save the file as Word Document?

I run the code:

package main
import (
    "github.com/unidoc/unioffice/document"
)
func main() {
    doc, _ := document.Open("word.docx")
    doc.SaveToFile("newfile.docx")
}

Expected Behavior

Expected file type is word document.

QQ图片20200213214717

Actual Behavior

But the newfile type is Strict Open Xml Document QQ图片20200213214722

github-actions[bot] commented 4 years ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

zgordan-vv commented 4 years ago

@GZLHZ can you tell your environment - OS, Office version? We cannot reproduce it so far

EP-Toushirou commented 4 years ago

@GZLHZ can you tell your environment - OS, Office version? We cannot reproduce it so far

OK win10 & office2019(or office 2010)

zgordan-vv commented 4 years ago

@GZLHZ Can you test a PR https://github.com/unidoc/unioffice/pull/399 with the code below:

package main

import (
    "github.com/unidoc/unioffice/document"
    st "github.com/unidoc/unioffice/schema/soo/ofc/sharedTypes"
)

func main() {
    doc, err := document.Open("document.docx")
    if err != nil {
        panic(err)
    }
    doc.SetStrict(false) // document will be saved as Word document (this is a default option for new files)
    doc.SaveToFile("conformance_transitional.docx")
    doc.SetStrict(true) // document will be saved in the Strict mode
    doc.SaveToFile("conformance_strict.docx")
    doc.SetConformance(st.ST_ConformanceClassUnset) // Conformance attribute will be unset, which also leads to saving as Word document
    doc.SaveToFile("conformance_unset.docx")
}
EP-Toushirou commented 4 years ago

@zgordan-vv Hi, I tested the master code, and it save as word document.It works now.Thank you!!