|
| 1 | +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of |
| 2 | +// this source code is governed by a BSD-style license that can be found in |
| 3 | +// the LICENSE file. |
| 4 | +// |
| 5 | +// Package excelize providing a set of functions that allow you to write to |
| 6 | +// and read from XLSX files. Support reads and writes XLSX file generated by |
| 7 | +// Microsoft Excel™ 2007 and later. Support save file without losing original |
| 8 | +// charts of XLSX. This library needs Go version 1.8 or later. |
| 9 | + |
| 10 | +package excelize |
| 11 | + |
| 12 | +import ( |
| 13 | + "path/filepath" |
| 14 | + "testing" |
| 15 | + |
| 16 | + "github.com/stretchr/testify/assert" |
| 17 | +) |
| 18 | + |
| 19 | +func TestSetDocProps(t *testing.T) { |
| 20 | + f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) |
| 21 | + if !assert.NoError(t, err) { |
| 22 | + t.FailNow() |
| 23 | + } |
| 24 | + assert.NoError(t, f.SetDocProps(&DocProperties{ |
| 25 | + Category: "category", |
| 26 | + ContentStatus: "Draft", |
| 27 | + Created: "2019-06-04T22:00:10Z", |
| 28 | + Creator: "Go Excelize", |
| 29 | + Description: "This file created by Go Excelize", |
| 30 | + Identifier: "xlsx", |
| 31 | + Keywords: "Spreadsheet", |
| 32 | + LastModifiedBy: "Go Author", |
| 33 | + Modified: "2019-06-04T22:00:10Z", |
| 34 | + Revision: "0", |
| 35 | + Subject: "Test Subject", |
| 36 | + Title: "Test Title", |
| 37 | + Language: "en-US", |
| 38 | + Version: "1.0.0", |
| 39 | + })) |
| 40 | + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetDocProps.xlsx"))) |
| 41 | + f.XLSX["docProps/core.xml"] = nil |
| 42 | + assert.EqualError(t, f.SetDocProps(&DocProperties{}), "EOF") |
| 43 | +} |
| 44 | + |
| 45 | +func TestGetDocProps(t *testing.T) { |
| 46 | + f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) |
| 47 | + if !assert.NoError(t, err) { |
| 48 | + t.FailNow() |
| 49 | + } |
| 50 | + props, err := f.GetDocProps() |
| 51 | + assert.NoError(t, err) |
| 52 | + assert.Equal(t, props.Creator, "Microsoft Office User") |
| 53 | + f.XLSX["docProps/core.xml"] = nil |
| 54 | + _, err = f.GetDocProps() |
| 55 | + assert.EqualError(t, err, "EOF") |
| 56 | +} |
0 commit comments