From f87c39c41ddcb2fbb75a6035ba1dd28e4de8c71b Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 17 Feb 2022 00:09:11 +0800 Subject: [PATCH] This closes #1148, resolve limitations when adding VBA project to the workbook Added two exported functions `SetWorkbookPrOptions` and `GetWorkbookPrOptions` to support setting and getting the code name property of the workbook Re-order fields of the workbook properties group to improve the compatibility Go Modules dependencies upgrade Put workbook related operating in new `workbook.go` source code Library introduction docs block updated --- adjust.go | 12 ++-- calc.go | 12 ++-- calcchain.go | 12 ++-- cell.go | 12 ++-- chart.go | 12 ++-- col.go | 12 ++-- comment.go | 12 ++-- comment_test.go | 12 ++-- crypt.go | 12 ++-- crypt_test.go | 12 ++-- datavalidation.go | 12 ++-- datavalidation_test.go | 12 ++-- date.go | 12 ++-- docProps.go | 12 ++-- docProps_test.go | 12 ++-- drawing.go | 12 ++-- drawing_test.go | 12 ++-- errors.go | 12 ++-- excelize.go | 12 ++-- file.go | 12 ++-- go.mod | 6 +- go.sum | 12 ++-- lib.go | 12 ++-- merge.go | 12 ++-- numfmt.go | 14 ++-- picture.go | 12 ++-- pivotTable.go | 12 ++-- rows.go | 12 ++-- shape.go | 12 ++-- sheet.go | 81 ++--------------------- sheetpr.go | 14 ++-- sheetview.go | 12 ++-- sparkline.go | 12 ++-- stream.go | 12 ++-- styles.go | 12 ++-- table.go | 12 ++-- templates.go | 12 ++-- vmlDrawing.go | 12 ++-- workbook.go | 147 +++++++++++++++++++++++++++++++++++++++++ workbook_test.go | 43 ++++++++++++ xmlApp.go | 12 ++-- xmlCalcChain.go | 12 ++-- xmlChart.go | 12 ++-- xmlChartSheet.go | 12 ++-- xmlComments.go | 12 ++-- xmlContentTypes.go | 12 ++-- xmlCore.go | 12 ++-- xmlDecodeDrawing.go | 12 ++-- xmlDrawing.go | 12 ++-- xmlPivotCache.go | 12 ++-- xmlPivotTable.go | 12 ++-- xmlSharedStrings.go | 12 ++-- xmlStyles.go | 12 ++-- xmlTable.go | 12 ++-- xmlTheme.go | 12 ++-- xmlWorkbook.go | 38 +++++------ xmlWorksheet.go | 12 ++-- 57 files changed, 532 insertions(+), 411 deletions(-) create mode 100644 workbook.go create mode 100644 workbook_test.go diff --git a/adjust.go b/adjust.go index bf3ad77..e1c0e15 100644 --- a/adjust.go +++ b/adjust.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/calc.go b/calc.go index b3c6df8..a4c45fb 100644 --- a/calc.go +++ b/calc.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/calcchain.go b/calcchain.go index 44a47c9..a1f9c0c 100644 --- a/calcchain.go +++ b/calcchain.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/cell.go b/cell.go index b5b6ed4..b6ddd35 100644 --- a/cell.go +++ b/cell.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/chart.go b/chart.go index bbd276e..4543770 100644 --- a/chart.go +++ b/chart.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/col.go b/col.go index 16d1f93..827d727 100644 --- a/col.go +++ b/col.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/comment.go b/comment.go index f3b3642..6cebfee 100644 --- a/comment.go +++ b/comment.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/comment_test.go b/comment_test.go index 1901f7f..952763d 100644 --- a/comment_test.go +++ b/comment_test.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/crypt.go b/crypt.go index 9912a67..c579a10 100644 --- a/crypt.go +++ b/crypt.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/crypt_test.go b/crypt_test.go index a81d72d..45e8815 100644 --- a/crypt_test.go +++ b/crypt_test.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/datavalidation.go b/datavalidation.go index b8f939b..d0e927b 100644 --- a/datavalidation.go +++ b/datavalidation.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/datavalidation_test.go b/datavalidation_test.go index eed1b03..9ef11dc 100644 --- a/datavalidation_test.go +++ b/datavalidation_test.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/date.go b/date.go index 04c9110..83d23cc 100644 --- a/date.go +++ b/date.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/docProps.go b/docProps.go index 44c30c8..41ea18e 100644 --- a/docProps.go +++ b/docProps.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/docProps_test.go b/docProps_test.go index 458280b..545059d 100644 --- a/docProps_test.go +++ b/docProps_test.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/drawing.go b/drawing.go index ac88032..0bc7900 100644 --- a/drawing.go +++ b/drawing.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/drawing_test.go b/drawing_test.go index fc89d47..d33977f 100644 --- a/drawing_test.go +++ b/drawing_test.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/errors.go b/errors.go index f0a3405..1047704 100644 --- a/errors.go +++ b/errors.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/excelize.go b/excelize.go index 2155f0a..0aebfc4 100644 --- a/excelize.go +++ b/excelize.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. // // See https://xuri.me/excelize for more information about this package. package excelize diff --git a/file.go b/file.go index 43d94b2..0cfed05 100644 --- a/file.go +++ b/file.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/go.mod b/go.mod index 9d6e88d..16874b2 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,9 @@ require ( github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/richardlehane/mscfb v1.0.4 github.com/stretchr/testify v1.7.0 - github.com/xuri/efp v0.0.0-20220201101309-d64cf20d930d - github.com/xuri/nfp v0.0.0-20220210053112-1df76b07693e - golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2 + github.com/xuri/efp v0.0.0-20220216053911-6d8731f62184 + github.com/xuri/nfp v0.0.0-20220215121256-71f1502108b5 + golang.org/x/crypto v0.0.0-20220214200702-86341886e292 golang.org/x/image v0.0.0-20211028202545-6944b10bf410 golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd golang.org/x/text v0.3.7 diff --git a/go.sum b/go.sum index efd0f63..a4051d4 100644 --- a/go.sum +++ b/go.sum @@ -11,12 +11,12 @@ github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTK github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/xuri/efp v0.0.0-20220201101309-d64cf20d930d h1:zFggKNM0CSDVuK4Gzd7RNw5hFCHOETKZ7Nb5MHw+bCE= -github.com/xuri/efp v0.0.0-20220201101309-d64cf20d930d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= -github.com/xuri/nfp v0.0.0-20220210053112-1df76b07693e h1:8Bg6HoC/EdUGR3Y9Vx12XoD/RfMta06hFamKO+NK7Bc= -github.com/xuri/nfp v0.0.0-20220210053112-1df76b07693e/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= -golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2 h1:XdAboW3BNMv9ocSCOk/u1MFioZGzCNkiJZ19v9Oe3Ig= -golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +github.com/xuri/efp v0.0.0-20220216053911-6d8731f62184 h1:9nchVQT/GVLRvOnXzx+wUvSublH/jG/ANV4MxBnGhUA= +github.com/xuri/efp v0.0.0-20220216053911-6d8731f62184/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= +github.com/xuri/nfp v0.0.0-20220215121256-71f1502108b5 h1:Pg6lKJe2FUZTalbUygJxgW1ke2re9lY3YW5TKb+Pxe4= +github.com/xuri/nfp v0.0.0-20220215121256-71f1502108b5/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= diff --git a/lib.go b/lib.go index 1bfdda2..47ce2fe 100644 --- a/lib.go +++ b/lib.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/merge.go b/merge.go index 3ba7d6a..376b68b 100644 --- a/merge.go +++ b/merge.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/numfmt.go b/numfmt.go index 1f41f19..4549110 100644 --- a/numfmt.go +++ b/numfmt.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize @@ -37,8 +37,8 @@ type numberFormat struct { ap, afterPoint, beforePoint, localCode, result, value, valueSectionType string } -// supportedTokenTypes list the supported number format token types currently. var ( + // supportedTokenTypes list the supported number format token types currently. supportedTokenTypes = []string{ nfp.TokenTypeCurrencyLanguage, nfp.TokenTypeDateTimes, diff --git a/picture.go b/picture.go index f018bd9..180983d 100644 --- a/picture.go +++ b/picture.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/pivotTable.go b/pivotTable.go index d7e9c94..5810968 100644 --- a/pivotTable.go +++ b/pivotTable.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/rows.go b/rows.go index 88df52c..0d2490c 100644 --- a/rows.go +++ b/rows.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/shape.go b/shape.go index be3735b..514171a 100644 --- a/shape.go +++ b/shape.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/sheet.go b/sheet.go index f10ca07..b440fb9 100644 --- a/sheet.go +++ b/sheet.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize @@ -93,35 +93,6 @@ func (f *File) contentTypesWriter() { } } -// getWorkbookPath provides a function to get the path of the workbook.xml in -// the spreadsheet. -func (f *File) getWorkbookPath() (path string) { - if rels := f.relsReader("_rels/.rels"); rels != nil { - rels.Lock() - defer rels.Unlock() - for _, rel := range rels.Relationships { - if rel.Type == SourceRelationshipOfficeDocument { - path = strings.TrimPrefix(rel.Target, "/") - return - } - } - } - return -} - -// getWorkbookRelsPath provides a function to get the path of the workbook.xml.rels -// in the spreadsheet. -func (f *File) getWorkbookRelsPath() (path string) { - wbPath := f.getWorkbookPath() - wbDir := filepath.Dir(wbPath) - if wbDir == "." { - path = "_rels/" + filepath.Base(wbPath) + ".rels" - return - } - path = strings.TrimPrefix(filepath.Dir(wbPath)+"/_rels/"+filepath.Base(wbPath)+".rels", "/") - return -} - // getWorksheetPath construct a target XML as xl/worksheets/sheet%d by split // path, compatible with different types of relative paths in // workbook.xml.rels, for example: worksheets/sheet%d.xml @@ -135,35 +106,6 @@ func (f *File) getWorksheetPath(relTarget string) (path string) { return path } -// workbookReader provides a function to get the pointer to the workbook.xml -// structure after deserialization. -func (f *File) workbookReader() *xlsxWorkbook { - var err error - if f.WorkBook == nil { - wbPath := f.getWorkbookPath() - f.WorkBook = new(xlsxWorkbook) - if _, ok := f.xmlAttr[wbPath]; !ok { - d := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))) - f.xmlAttr[wbPath] = append(f.xmlAttr[wbPath], getRootElement(d)...) - f.addNameSpaces(wbPath, SourceRelationship) - } - if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))). - Decode(f.WorkBook); err != nil && err != io.EOF { - log.Printf("xml decode error: %s", err) - } - } - return f.WorkBook -} - -// workBookWriter provides a function to save workbook.xml after serialize -// structure. -func (f *File) workBookWriter() { - if f.WorkBook != nil { - output, _ := xml.Marshal(f.WorkBook) - f.saveFileList(f.getWorkbookPath(), replaceRelationshipsBytes(f.replaceNameSpaceBytes(f.getWorkbookPath(), output))) - } -} - // mergeExpandedCols merge expanded columns. func (f *File) mergeExpandedCols(ws *xlsxWorksheet) { sort.Slice(ws.Cols.Col, func(i, j int) bool { @@ -276,17 +218,6 @@ func (f *File) setSheet(index int, name string) { f.xmlAttr[path] = []xml.Attr{NameSpaceSpreadSheet} } -// setWorkbook update workbook property of the spreadsheet. Maximum 31 -// characters are allowed in sheet title. -func (f *File) setWorkbook(name string, sheetID, rid int) { - content := f.workbookReader() - content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ - Name: trimSheetName(name), - SheetID: sheetID, - ID: "rId" + strconv.Itoa(rid), - }) -} - // relsWriter provides a function to save relationships after // serialize structure. func (f *File) relsWriter() { diff --git a/sheetpr.go b/sheetpr.go index d7e6d2a..e8e6e9d 100644 --- a/sheetpr.go +++ b/sheetpr.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize @@ -25,7 +25,7 @@ type SheetPrOptionPtr interface { } type ( - // CodeName is a SheetPrOption + // CodeName is an option used for SheetPrOption and WorkbookPrOption CodeName string // EnableFormatConditionsCalculation is a SheetPrOption EnableFormatConditionsCalculation bool diff --git a/sheetview.go b/sheetview.go index b0912ec..8650b32 100644 --- a/sheetview.go +++ b/sheetview.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/sparkline.go b/sparkline.go index b75a2f1..5a480b9 100644 --- a/sparkline.go +++ b/sparkline.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/stream.go b/stream.go index 3551e8f..a9ec2cf 100644 --- a/stream.go +++ b/stream.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/styles.go b/styles.go index 6dea20e..6d6d7bb 100644 --- a/styles.go +++ b/styles.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/table.go b/table.go index 961f9e6..1fcb448 100644 --- a/table.go +++ b/table.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/templates.go b/templates.go index d08f45f..9468341 100644 --- a/templates.go +++ b/templates.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. // // This file contains default templates for XML files we don't yet populated // based on content. diff --git a/vmlDrawing.go b/vmlDrawing.go index 418b4c5..f9de499 100644 --- a/vmlDrawing.go +++ b/vmlDrawing.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/workbook.go b/workbook.go new file mode 100644 index 0000000..a2263b2 --- /dev/null +++ b/workbook.go @@ -0,0 +1,147 @@ +// Copyright 2016 - 2022 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 XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. + +package excelize + +import ( + "bytes" + "encoding/xml" + "io" + "log" + "path/filepath" + "strconv" + "strings" +) + +// WorkbookPrOption is an option of a view of a workbook. See SetWorkbookPrOptions(). +type WorkbookPrOption interface { + setWorkbookPrOption(pr *xlsxWorkbookPr) +} + +// WorkbookPrOptionPtr is a writable WorkbookPrOption. See GetWorkbookPrOptions(). +type WorkbookPrOptionPtr interface { + WorkbookPrOption + getWorkbookPrOption(pr *xlsxWorkbookPr) +} + +// setWorkbook update workbook property of the spreadsheet. Maximum 31 +// characters are allowed in sheet title. +func (f *File) setWorkbook(name string, sheetID, rid int) { + content := f.workbookReader() + content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ + Name: trimSheetName(name), + SheetID: sheetID, + ID: "rId" + strconv.Itoa(rid), + }) +} + +// getWorkbookPath provides a function to get the path of the workbook.xml in +// the spreadsheet. +func (f *File) getWorkbookPath() (path string) { + if rels := f.relsReader("_rels/.rels"); rels != nil { + rels.Lock() + defer rels.Unlock() + for _, rel := range rels.Relationships { + if rel.Type == SourceRelationshipOfficeDocument { + path = strings.TrimPrefix(rel.Target, "/") + return + } + } + } + return +} + +// getWorkbookRelsPath provides a function to get the path of the workbook.xml.rels +// in the spreadsheet. +func (f *File) getWorkbookRelsPath() (path string) { + wbPath := f.getWorkbookPath() + wbDir := filepath.Dir(wbPath) + if wbDir == "." { + path = "_rels/" + filepath.Base(wbPath) + ".rels" + return + } + path = strings.TrimPrefix(filepath.Dir(wbPath)+"/_rels/"+filepath.Base(wbPath)+".rels", "/") + return +} + +// workbookReader provides a function to get the pointer to the workbook.xml +// structure after deserialization. +func (f *File) workbookReader() *xlsxWorkbook { + var err error + if f.WorkBook == nil { + wbPath := f.getWorkbookPath() + f.WorkBook = new(xlsxWorkbook) + if _, ok := f.xmlAttr[wbPath]; !ok { + d := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))) + f.xmlAttr[wbPath] = append(f.xmlAttr[wbPath], getRootElement(d)...) + f.addNameSpaces(wbPath, SourceRelationship) + } + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))). + Decode(f.WorkBook); err != nil && err != io.EOF { + log.Printf("xml decode error: %s", err) + } + } + return f.WorkBook +} + +// workBookWriter provides a function to save workbook.xml after serialize +// structure. +func (f *File) workBookWriter() { + if f.WorkBook != nil { + output, _ := xml.Marshal(f.WorkBook) + f.saveFileList(f.getWorkbookPath(), replaceRelationshipsBytes(f.replaceNameSpaceBytes(f.getWorkbookPath(), output))) + } +} + +// SetWorkbookPrOptions provides a function to sets workbook properties. +// +// Available options: +// CodeName(string) +func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error { + wb := f.workbookReader() + pr := wb.WorkbookPr + if pr == nil { + pr = new(xlsxWorkbookPr) + wb.WorkbookPr = pr + } + for _, opt := range opts { + opt.setWorkbookPrOption(pr) + } + return nil +} + +// setWorkbookPrOption implements the WorkbookPrOption interface. +func (o CodeName) setWorkbookPrOption(pr *xlsxWorkbookPr) { + pr.CodeName = string(o) +} + +// GetWorkbookPrOptions provides a function to gets workbook properties. +// +// Available options: +// CodeName(string) +func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error { + wb := f.workbookReader() + pr := wb.WorkbookPr + for _, opt := range opts { + opt.getWorkbookPrOption(pr) + } + return nil +} + +// getWorkbookPrOption implements the WorkbookPrOption interface and get the +// code name of thw workbook. +func (o *CodeName) getWorkbookPrOption(pr *xlsxWorkbookPr) { + if pr == nil { + *o = "" + return + } + *o = CodeName(pr.CodeName) +} diff --git a/workbook_test.go b/workbook_test.go new file mode 100644 index 0000000..90fc3d7 --- /dev/null +++ b/workbook_test.go @@ -0,0 +1,43 @@ +package excelize + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func ExampleFile_SetWorkbookPrOptions() { + f := NewFile() + if err := f.SetWorkbookPrOptions( + CodeName("code"), + ); err != nil { + fmt.Println(err) + } + // Output: +} + +func ExampleFile_GetWorkbookPrOptions() { + f := NewFile() + var codeName CodeName + if err := f.GetWorkbookPrOptions(&codeName); err != nil { + fmt.Println(err) + } + fmt.Println("Defaults:") + fmt.Printf("- codeName: %q\n", codeName) + // Output: + // Defaults: + // - codeName: "" +} + +func TestWorkbookPr(t *testing.T) { + f := NewFile() + wb := f.workbookReader() + wb.WorkbookPr = nil + var codeName CodeName + assert.NoError(t, f.GetWorkbookPrOptions(&codeName)) + assert.Equal(t, "", string(codeName)) + assert.NoError(t, f.SetWorkbookPrOptions(CodeName("code"))) + assert.NoError(t, f.GetWorkbookPrOptions(&codeName)) + assert.Equal(t, "code", string(codeName)) +} diff --git a/xmlApp.go b/xmlApp.go index 215ed23..abfd82b 100644 --- a/xmlApp.go +++ b/xmlApp.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlCalcChain.go b/xmlCalcChain.go index b8645f5..401bf2c 100644 --- a/xmlCalcChain.go +++ b/xmlCalcChain.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlChart.go b/xmlChart.go index 3725845..2e1e958 100644 --- a/xmlChart.go +++ b/xmlChart.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlChartSheet.go b/xmlChartSheet.go index 0e868f2..f0f2f62 100644 --- a/xmlChartSheet.go +++ b/xmlChartSheet.go @@ -4,12 +4,12 @@ // // struct code generated by github.com/xuri/xgen // -// Package excelize providing a set of functions that allow you to write to -// and read from XLSX / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlComments.go b/xmlComments.go index 8f7a03d..b4602fc 100644 --- a/xmlComments.go +++ b/xmlComments.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlContentTypes.go b/xmlContentTypes.go index 2f47f94..5920f1f 100644 --- a/xmlContentTypes.go +++ b/xmlContentTypes.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlCore.go b/xmlCore.go index 9aa09bf..22ae6bc 100644 --- a/xmlCore.go +++ b/xmlCore.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlDecodeDrawing.go b/xmlDecodeDrawing.go index 0ca63d1..9091440 100644 --- a/xmlDecodeDrawing.go +++ b/xmlDecodeDrawing.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlDrawing.go b/xmlDrawing.go index 61c25ca..c96034c 100644 --- a/xmlDrawing.go +++ b/xmlDrawing.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlPivotCache.go b/xmlPivotCache.go index 9591858..0af7c44 100644 --- a/xmlPivotCache.go +++ b/xmlPivotCache.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlPivotTable.go b/xmlPivotTable.go index a7543a7..897669b 100644 --- a/xmlPivotTable.go +++ b/xmlPivotTable.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlSharedStrings.go b/xmlSharedStrings.go index 3b4bb7a..683105e 100644 --- a/xmlSharedStrings.go +++ b/xmlSharedStrings.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlStyles.go b/xmlStyles.go index a9c3f3b..c70ab60 100644 --- a/xmlStyles.go +++ b/xmlStyles.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlTable.go b/xmlTable.go index 2fc8f4d..4afc26d 100644 --- a/xmlTable.go +++ b/xmlTable.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlTheme.go b/xmlTheme.go index 9e10bdd..6b9e207 100644 --- a/xmlTheme.go +++ b/xmlTheme.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize diff --git a/xmlWorkbook.go b/xmlWorkbook.go index 59e7601..f014bee 100644 --- a/xmlWorkbook.go +++ b/xmlWorkbook.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize @@ -107,24 +107,24 @@ type xlsxFileVersion struct { // http://schemas.openxmlformats.org/spreadsheetml/2006/main This element // defines a collection of workbook properties. type xlsxWorkbookPr struct { - AllowRefreshQuery bool `xml:"allowRefreshQuery,attr,omitempty"` - AutoCompressPictures bool `xml:"autoCompressPictures,attr,omitempty"` - BackupFile bool `xml:"backupFile,attr,omitempty"` - CheckCompatibility bool `xml:"checkCompatibility,attr,omitempty"` - CodeName string `xml:"codeName,attr,omitempty"` Date1904 bool `xml:"date1904,attr,omitempty"` - DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"` + ShowObjects string `xml:"showObjects,attr,omitempty"` + ShowBorderUnselectedTables *bool `xml:"showBorderUnselectedTables,attr"` FilterPrivacy bool `xml:"filterPrivacy,attr,omitempty"` - HidePivotFieldList bool `xml:"hidePivotFieldList,attr,omitempty"` PromptedSolutions bool `xml:"promptedSolutions,attr,omitempty"` + ShowInkAnnotation *bool `xml:"showInkAnnotation,attr"` + BackupFile bool `xml:"backupFile,attr,omitempty"` + SaveExternalLinkValues *bool `xml:"saveExternalLinkValues,attr"` + UpdateLinks string `xml:"updateLinks,attr,omitempty"` + CodeName string `xml:"codeName,attr,omitempty"` + HidePivotFieldList bool `xml:"hidePivotFieldList,attr,omitempty"` + ShowPivotChartFilter bool `xml:"showPivotChartFilter,attr,omitempty"` + AllowRefreshQuery bool `xml:"allowRefreshQuery,attr,omitempty"` PublishItems bool `xml:"publishItems,attr,omitempty"` + CheckCompatibility bool `xml:"checkCompatibility,attr,omitempty"` + AutoCompressPictures *bool `xml:"autoCompressPictures,attr"` RefreshAllConnections bool `xml:"refreshAllConnections,attr,omitempty"` - SaveExternalLinkValues bool `xml:"saveExternalLinkValues,attr,omitempty"` - ShowBorderUnselectedTables bool `xml:"showBorderUnselectedTables,attr,omitempty"` - ShowInkAnnotation bool `xml:"showInkAnnotation,attr,omitempty"` - ShowObjects string `xml:"showObjects,attr,omitempty"` - ShowPivotChartFilter bool `xml:"showPivotChartFilter,attr,omitempty"` - UpdateLinks string `xml:"updateLinks,attr,omitempty"` + DefaultThemeVersion string `xml:"defaultThemeVersion,attr,omitempty"` } // xlsxBookViews directly maps the bookViews element. This element specifies the diff --git a/xmlWorksheet.go b/xmlWorksheet.go index 83dd1ba..4a9c88a 100644 --- a/xmlWorksheet.go +++ b/xmlWorksheet.go @@ -2,12 +2,12 @@ // 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 / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize