From cff16fa8118291fd885f3f3f75fa07e28bba5eec Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 5 Jun 2019 22:06:15 +0800 Subject: - Supplemental worksheet struct fields and field order adjustment - Testing case for set and get doc properties - Update charts struct XML tags --- docProps_test.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 docProps_test.go (limited to 'docProps_test.go') diff --git a/docProps_test.go b/docProps_test.go new file mode 100644 index 0000000..1f52beb --- /dev/null +++ b/docProps_test.go @@ -0,0 +1,56 @@ +// Copyright 2016 - 2019 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.8 or later. + +package excelize + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +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.EqualError(t, f.SetDocProps(&DocProperties{}), "EOF") +} + +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.EqualError(t, err, "EOF") +} -- cgit v1.2.1