@@ -65,34 +65,15 @@ import (
6565// AppVersion: "16.0000",
6666// })
6767func (f * File ) SetAppProps (appProperties * AppProperties ) error {
68- var (
69- app * xlsxProperties
70- err error
71- field string
72- fields []string
73- immutable , mutable reflect.Value
74- output []byte
75- )
76- app = new (xlsxProperties )
77- if err = f .xmlNewDecoder (bytes .NewReader (namespaceStrictToTransitional (f .readXML (defaultXMLPathDocPropsApp )))).
68+ app := new (xlsxProperties )
69+ if err := f .xmlNewDecoder (bytes .NewReader (namespaceStrictToTransitional (f .readXML (defaultXMLPathDocPropsApp )))).
7870 Decode (app ); err != nil && err != io .EOF {
7971 return err
8072 }
81- fields = []string {"Application" , "ScaleCrop" , "DocSecurity" , "Company" , "LinksUpToDate" , "HyperlinksChanged" , "AppVersion" }
82- immutable , mutable = reflect .ValueOf (* appProperties ), reflect .ValueOf (app ).Elem ()
83- for _ , field = range fields {
84- immutableField := immutable .FieldByName (field )
85- switch immutableField .Kind () {
86- case reflect .Bool :
87- mutable .FieldByName (field ).SetBool (immutableField .Bool ())
88- case reflect .Int :
89- mutable .FieldByName (field ).SetInt (immutableField .Int ())
90- default :
91- mutable .FieldByName (field ).SetString (immutableField .String ())
92- }
93- }
73+ setNoPtrFieldsVal ([]string {"Application" , "ScaleCrop" , "DocSecurity" , "Company" , "LinksUpToDate" , "HyperlinksChanged" , "AppVersion" },
74+ reflect .ValueOf (* appProperties ), reflect .ValueOf (app ).Elem ())
9475 app .Vt = NameSpaceDocumentPropertiesVariantTypes .Value
95- output , err = xml .Marshal (app )
76+ output , err : = xml .Marshal (app )
9677 f .saveFileList (defaultXMLPathDocPropsApp , output )
9778 return err
9879}
@@ -180,22 +161,12 @@ func (f *File) GetAppProps() (ret *AppProperties, err error) {
180161// Version: "1.0.0",
181162// })
182163func (f * File ) SetDocProps (docProperties * DocProperties ) error {
183- var (
184- core * decodeCoreProperties
185- err error
186- field , val string
187- fields []string
188- immutable , mutable reflect.Value
189- newProps * xlsxCoreProperties
190- output []byte
191- )
192-
193- core = new (decodeCoreProperties )
194- if err = f .xmlNewDecoder (bytes .NewReader (namespaceStrictToTransitional (f .readXML (defaultXMLPathDocPropsCore )))).
164+ core := new (decodeCoreProperties )
165+ if err := f .xmlNewDecoder (bytes .NewReader (namespaceStrictToTransitional (f .readXML (defaultXMLPathDocPropsCore )))).
195166 Decode (core ); err != nil && err != io .EOF {
196167 return err
197168 }
198- newProps = & xlsxCoreProperties {
169+ newProps : = & xlsxCoreProperties {
199170 Dc : NameSpaceDublinCore ,
200171 Dcterms : NameSpaceDublinCoreTerms ,
201172 Dcmitype : NameSpaceDublinCoreMetadataInitiative ,
@@ -219,23 +190,17 @@ func (f *File) SetDocProps(docProperties *DocProperties) error {
219190 if core .Modified != nil {
220191 newProps .Modified = & xlsxDcTerms {Type : core .Modified .Type , Text : core .Modified .Text }
221192 }
222- fields = []string {
193+ setNoPtrFieldsVal ( []string {
223194 "Category" , "ContentStatus" , "Creator" , "Description" , "Identifier" , "Keywords" ,
224195 "LastModifiedBy" , "Revision" , "Subject" , "Title" , "Language" , "Version" ,
225- }
226- immutable , mutable = reflect .ValueOf (* docProperties ), reflect .ValueOf (newProps ).Elem ()
227- for _ , field = range fields {
228- if val = immutable .FieldByName (field ).String (); val != "" {
229- mutable .FieldByName (field ).SetString (val )
230- }
231- }
196+ }, reflect .ValueOf (* docProperties ), reflect .ValueOf (newProps ).Elem ())
232197 if docProperties .Created != "" {
233198 newProps .Created = & xlsxDcTerms {Type : "dcterms:W3CDTF" , Text : docProperties .Created }
234199 }
235200 if docProperties .Modified != "" {
236201 newProps .Modified = & xlsxDcTerms {Type : "dcterms:W3CDTF" , Text : docProperties .Modified }
237202 }
238- output , err = xml .Marshal (newProps )
203+ output , err : = xml .Marshal (newProps )
239204 f .saveFileList (defaultXMLPathDocPropsCore , output )
240205
241206 return err
0 commit comments