From e37724c22b95de974f0235e992236d555aa6ad12 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 14 Jul 2022 00:17:51 +0800 Subject: This fix potential panic and file corrupted - Fix the panic when set or get sheet view options on the sheet without views options - Fix generated workbook corruption caused by empty created or modified dcterms in the document core properties - Update the unit tests --- docProps.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'docProps.go') diff --git a/docProps.go b/docProps.go index 41ea18e..fe6f214 100644 --- a/docProps.go +++ b/docProps.go @@ -204,7 +204,12 @@ func (f *File) SetDocProps(docProperties *DocProperties) (err error) { Category: core.Category, Version: core.Version, }, nil - newProps.Created.Text, newProps.Created.Type, newProps.Modified.Text, newProps.Modified.Type = core.Created.Text, core.Created.Type, core.Modified.Text, core.Modified.Type + if core.Created != nil { + newProps.Created = &xlsxDcTerms{Type: core.Created.Type, Text: core.Created.Text} + } + if core.Modified != nil { + newProps.Modified = &xlsxDcTerms{Type: core.Modified.Type, Text: core.Modified.Text} + } fields = []string{ "Category", "ContentStatus", "Creator", "Description", "Identifier", "Keywords", "LastModifiedBy", "Revision", "Subject", "Title", "Language", "Version", @@ -216,10 +221,10 @@ func (f *File) SetDocProps(docProperties *DocProperties) (err error) { } } if docProperties.Created != "" { - newProps.Created.Text = docProperties.Created + newProps.Created = &xlsxDcTerms{Type: "dcterms:W3CDTF", Text: docProperties.Created} } if docProperties.Modified != "" { - newProps.Modified.Text = docProperties.Modified + newProps.Modified = &xlsxDcTerms{Type: "dcterms:W3CDTF", Text: docProperties.Modified} } output, err = xml.Marshal(newProps) f.saveFileList(defaultXMLPathDocPropsCore, output) @@ -239,19 +244,22 @@ func (f *File) GetDocProps() (ret *DocProperties, err error) { ret, err = &DocProperties{ Category: core.Category, ContentStatus: core.ContentStatus, - Created: core.Created.Text, Creator: core.Creator, Description: core.Description, Identifier: core.Identifier, Keywords: core.Keywords, LastModifiedBy: core.LastModifiedBy, - Modified: core.Modified.Text, Revision: core.Revision, Subject: core.Subject, Title: core.Title, Language: core.Language, Version: core.Version, }, nil - + if core.Created != nil { + ret.Created = core.Created.Text + } + if core.Modified != nil { + ret.Modified = core.Modified.Text + } return } -- cgit v1.2.1