mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
document.SetConformance is added with an example (#399)
* document.SetConformance is added with an example * SetStrict is added as shortcut * 2020 * preserve conformance attr * fix
This commit is contained in:
parent
cd8c690655
commit
56b03a8aed
BIN
_examples/document/set-strict/document.docx
Normal file
BIN
_examples/document/set-strict/document.docx
Normal file
Binary file not shown.
21
_examples/document/set-strict/main.go
Normal file
21
_examples/document/set-strict/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
||||
|
||||
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")
|
||||
}
|
@ -665,6 +665,7 @@ func Read(r io.ReaderAt, size int64) (*Document, error) {
|
||||
doc.createCustomProperties()
|
||||
}
|
||||
|
||||
ca := doc.x.ConformanceAttr
|
||||
decMap := zippkg.DecodeMap{}
|
||||
decMap.SetOnNewRelationshipFunc(doc.onNewRelationship)
|
||||
// we should discover all contents by starting with these two files
|
||||
@ -673,6 +674,7 @@ func Read(r io.ReaderAt, size int64) (*Document, error) {
|
||||
if err := decMap.Decode(files); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc.x.ConformanceAttr = ca
|
||||
|
||||
for _, f := range files {
|
||||
if f == nil {
|
||||
@ -1150,6 +1152,24 @@ func (d Document) Bookmarks() []Bookmark {
|
||||
return ret
|
||||
}
|
||||
|
||||
// SetConformance sets conformance attribute of the document
|
||||
// as one of these values from github.com/unidoc/unioffice/schema/soo/ofc/sharedTypes:
|
||||
// ST_ConformanceClassUnset, ST_ConformanceClassStrict or ST_ConformanceClassTransitional.
|
||||
func (d Document) SetConformance(conformanceAttr st.ST_ConformanceClass) {
|
||||
d.x.ConformanceAttr = conformanceAttr
|
||||
}
|
||||
|
||||
// SetStrict is a shortcut for document.SetConformance,
|
||||
// as one of these values from github.com/unidoc/unioffice/schema/soo/ofc/sharedTypes:
|
||||
// ST_ConformanceClassUnset, ST_ConformanceClassStrict or ST_ConformanceClassTransitional.
|
||||
func (d Document) SetStrict(strict bool) {
|
||||
if strict {
|
||||
d.x.ConformanceAttr = st.ST_ConformanceClassStrict
|
||||
} else {
|
||||
d.x.ConformanceAttr = st.ST_ConformanceClassTransitional
|
||||
}
|
||||
}
|
||||
|
||||
func getBool(onOff *wml.CT_OnOff) bool {
|
||||
return onOff != nil
|
||||
}
|
||||
|
BIN
document/testdata/issue198.docx.golden
vendored
BIN
document/testdata/issue198.docx.golden
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user