docProps_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.10 or later.
  9. package excelize
  10. import (
  11. "path/filepath"
  12. "testing"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestSetDocProps(t *testing.T) {
  16. f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
  17. if !assert.NoError(t, err) {
  18. t.FailNow()
  19. }
  20. assert.NoError(t, f.SetDocProps(&DocProperties{
  21. Category: "category",
  22. ContentStatus: "Draft",
  23. Created: "2019-06-04T22:00:10Z",
  24. Creator: "Go Excelize",
  25. Description: "This file created by Go Excelize",
  26. Identifier: "xlsx",
  27. Keywords: "Spreadsheet",
  28. LastModifiedBy: "Go Author",
  29. Modified: "2019-06-04T22:00:10Z",
  30. Revision: "0",
  31. Subject: "Test Subject",
  32. Title: "Test Title",
  33. Language: "en-US",
  34. Version: "1.0.0",
  35. }))
  36. assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetDocProps.xlsx")))
  37. f.XLSX["docProps/core.xml"] = nil
  38. assert.NoError(t, f.SetDocProps(&DocProperties{}))
  39. }
  40. func TestGetDocProps(t *testing.T) {
  41. f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
  42. if !assert.NoError(t, err) {
  43. t.FailNow()
  44. }
  45. props, err := f.GetDocProps()
  46. assert.NoError(t, err)
  47. assert.Equal(t, props.Creator, "Microsoft Office User")
  48. f.XLSX["docProps/core.xml"] = nil
  49. _, err = f.GetDocProps()
  50. assert.NoError(t, err)
  51. }