diff options
author | xuri <xuri.me@gmail.com> | 2020-05-22 16:53:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 16:53:46 +0800 |
commit | ec14de32f0c06f7a26b6b79578f666c0cc50b72c (patch) | |
tree | c6ebd61a7d9a7da5b993ffb82e4fb6c036e75d6a /docProps_test.go | |
parent | aa7eadbffe6ae2f9f86201bbaaa4c1d1e8829cae (diff) | |
parent | 2efc7107ff30dc7f1e1a798082616ee488f99489 (diff) |
Merge branch 'master' into fix/cell_lock
Diffstat (limited to 'docProps_test.go')
-rw-r--r-- | docProps_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/docProps_test.go b/docProps_test.go new file mode 100644 index 0000000..ef930ae --- /dev/null +++ b/docProps_test.go @@ -0,0 +1,69 @@ +// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excelâ„¢ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.10 or later. + +package excelize + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +var MacintoshCyrillicCharset = []byte{0x8F, 0xF0, 0xE8, 0xE2, 0xE5, 0xF2, 0x20, 0xEC, 0xE8, 0xF0} + +func TestSetDocProps(t *testing.T) { + f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) + if !assert.NoError(t, err) { + t.FailNow() + } + assert.NoError(t, f.SetDocProps(&DocProperties{ + Category: "category", + ContentStatus: "Draft", + Created: "2019-06-04T22:00:10Z", + Creator: "Go Excelize", + Description: "This file created by Go Excelize", + Identifier: "xlsx", + Keywords: "Spreadsheet", + LastModifiedBy: "Go Author", + Modified: "2019-06-04T22:00:10Z", + Revision: "0", + Subject: "Test Subject", + Title: "Test Title", + Language: "en-US", + Version: "1.0.0", + })) + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetDocProps.xlsx"))) + f.XLSX["docProps/core.xml"] = nil + assert.NoError(t, f.SetDocProps(&DocProperties{})) + + // Test unsupport charset + f = NewFile() + f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset + assert.EqualError(t, f.SetDocProps(&DocProperties{}), "xml decode error: XML syntax error on line 1: invalid UTF-8") +} + +func TestGetDocProps(t *testing.T) { + f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) + if !assert.NoError(t, err) { + t.FailNow() + } + props, err := f.GetDocProps() + assert.NoError(t, err) + assert.Equal(t, props.Creator, "Microsoft Office User") + f.XLSX["docProps/core.xml"] = nil + _, err = f.GetDocProps() + assert.NoError(t, err) + + // Test unsupport charset + f = NewFile() + f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset + _, err = f.GetDocProps() + assert.EqualError(t, err, "xml decode error: XML syntax error on line 1: invalid UTF-8") +} |