2020-10-04 21:07:39 +08:00
|
|
|
package excelize
|
2017-11-14 22:09:50 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mohae/deepcopy"
|
2018-12-27 18:51:44 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-11-14 22:09:50 +08:00
|
|
|
)
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
var _ = []SheetPrOption{
|
|
|
|
CodeName("hello"),
|
|
|
|
EnableFormatConditionsCalculation(false),
|
|
|
|
Published(false),
|
|
|
|
FitToPage(true),
|
2021-02-16 00:02:14 +08:00
|
|
|
TabColor("#FFFF00"),
|
2020-10-04 21:07:39 +08:00
|
|
|
AutoPageBreaks(true),
|
|
|
|
OutlineSummaryBelow(true),
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
var _ = []SheetPrOptionPtr{
|
|
|
|
(*CodeName)(nil),
|
|
|
|
(*EnableFormatConditionsCalculation)(nil),
|
|
|
|
(*Published)(nil),
|
|
|
|
(*FitToPage)(nil),
|
2021-02-16 00:02:14 +08:00
|
|
|
(*TabColor)(nil),
|
2020-10-04 21:07:39 +08:00
|
|
|
(*AutoPageBreaks)(nil),
|
|
|
|
(*OutlineSummaryBelow)(nil),
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_SetSheetPrOptions() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2017-11-14 22:09:50 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
2019-04-30 18:39:27 +08:00
|
|
|
if err := f.SetSheetPrOptions(sheet,
|
2020-10-04 21:07:39 +08:00
|
|
|
CodeName("code"),
|
|
|
|
EnableFormatConditionsCalculation(false),
|
|
|
|
Published(false),
|
|
|
|
FitToPage(true),
|
2021-02-16 00:02:14 +08:00
|
|
|
TabColor("#FFFF00"),
|
2020-10-04 21:07:39 +08:00
|
|
|
AutoPageBreaks(true),
|
|
|
|
OutlineSummaryBelow(false),
|
2017-11-14 22:09:50 +08:00
|
|
|
); err != nil {
|
2020-02-19 00:08:10 +08:00
|
|
|
fmt.Println(err)
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
// Output:
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_GetSheetPrOptions() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2017-11-14 22:09:50 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
var (
|
2020-10-04 21:07:39 +08:00
|
|
|
codeName CodeName
|
|
|
|
enableFormatConditionsCalculation EnableFormatConditionsCalculation
|
|
|
|
published Published
|
|
|
|
fitToPage FitToPage
|
2021-02-16 00:02:14 +08:00
|
|
|
tabColor TabColor
|
2020-10-04 21:07:39 +08:00
|
|
|
autoPageBreaks AutoPageBreaks
|
|
|
|
outlineSummaryBelow OutlineSummaryBelow
|
2017-11-14 22:09:50 +08:00
|
|
|
)
|
|
|
|
|
2019-04-30 18:39:27 +08:00
|
|
|
if err := f.GetSheetPrOptions(sheet,
|
2017-11-14 22:09:50 +08:00
|
|
|
&codeName,
|
|
|
|
&enableFormatConditionsCalculation,
|
|
|
|
&published,
|
|
|
|
&fitToPage,
|
2021-02-16 00:02:14 +08:00
|
|
|
&tabColor,
|
2017-11-14 22:09:50 +08:00
|
|
|
&autoPageBreaks,
|
2018-12-14 03:01:36 +08:00
|
|
|
&outlineSummaryBelow,
|
2017-11-14 22:09:50 +08:00
|
|
|
); err != nil {
|
2020-02-19 00:08:10 +08:00
|
|
|
fmt.Println(err)
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
fmt.Println("Defaults:")
|
|
|
|
fmt.Printf("- codeName: %q\n", codeName)
|
|
|
|
fmt.Println("- enableFormatConditionsCalculation:", enableFormatConditionsCalculation)
|
|
|
|
fmt.Println("- published:", published)
|
|
|
|
fmt.Println("- fitToPage:", fitToPage)
|
2021-02-16 00:02:14 +08:00
|
|
|
fmt.Printf("- tabColor: %q\n", tabColor)
|
2017-11-14 22:09:50 +08:00
|
|
|
fmt.Println("- autoPageBreaks:", autoPageBreaks)
|
2018-12-14 03:01:36 +08:00
|
|
|
fmt.Println("- outlineSummaryBelow:", outlineSummaryBelow)
|
2017-11-14 22:09:50 +08:00
|
|
|
// Output:
|
|
|
|
// Defaults:
|
|
|
|
// - codeName: ""
|
|
|
|
// - enableFormatConditionsCalculation: true
|
|
|
|
// - published: true
|
|
|
|
// - fitToPage: false
|
2021-02-16 00:02:14 +08:00
|
|
|
// - tabColor: ""
|
2017-11-14 22:09:50 +08:00
|
|
|
// - autoPageBreaks: false
|
2018-12-14 03:01:36 +08:00
|
|
|
// - outlineSummaryBelow: true
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSheetPrOptions(t *testing.T) {
|
|
|
|
const sheet = "Sheet1"
|
2018-12-27 18:51:44 +08:00
|
|
|
|
|
|
|
testData := []struct {
|
2020-10-04 21:07:39 +08:00
|
|
|
container SheetPrOptionPtr
|
|
|
|
nonDefault SheetPrOption
|
2017-11-14 22:09:50 +08:00
|
|
|
}{
|
2020-10-04 21:07:39 +08:00
|
|
|
{new(CodeName), CodeName("xx")},
|
|
|
|
{new(EnableFormatConditionsCalculation), EnableFormatConditionsCalculation(false)},
|
|
|
|
{new(Published), Published(false)},
|
|
|
|
{new(FitToPage), FitToPage(true)},
|
2021-02-16 00:02:14 +08:00
|
|
|
{new(TabColor), TabColor("FFFF00")},
|
2020-10-04 21:07:39 +08:00
|
|
|
{new(AutoPageBreaks), AutoPageBreaks(true)},
|
|
|
|
{new(OutlineSummaryBelow), OutlineSummaryBelow(false)},
|
2018-12-27 18:51:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range testData {
|
|
|
|
t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {
|
|
|
|
|
|
|
|
opt := test.nonDefault
|
|
|
|
t.Logf("option %T", opt)
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
def := deepcopy.Copy(test.container).(SheetPrOptionPtr)
|
|
|
|
val1 := deepcopy.Copy(def).(SheetPrOptionPtr)
|
|
|
|
val2 := deepcopy.Copy(def).(SheetPrOptionPtr)
|
2018-12-27 18:51:44 +08:00
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2018-12-27 18:51:44 +08:00
|
|
|
// Get the default value
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, def), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
// Get again and check
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, val1), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
if !assert.Equal(t, val1, def, opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set the same value
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.SetSheetPrOptions(sheet, val1), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
// Get again and check
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, val1), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set a different value
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.SetSheetPrOptions(sheet, test.nonDefault), opt)
|
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, val1), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
// Get again and compare
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, val2), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
if !assert.Equal(t, val1, val2, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Value should not be the same as the default
|
|
|
|
if !assert.NotEqual(t, def, val1, "%T: value should have changed from default", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Restore the default value
|
2019-04-30 18:39:27 +08:00
|
|
|
assert.NoError(t, f.SetSheetPrOptions(sheet, def), opt)
|
|
|
|
assert.NoError(t, f.GetSheetPrOptions(sheet, val1), opt)
|
2018-12-27 18:51:44 +08:00
|
|
|
if !assert.Equal(t, def, val1) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
})
|
2017-11-14 22:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-16 01:03:29 +08:00
|
|
|
|
|
|
|
func TestSetSheetrOptions(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2021-02-16 00:02:14 +08:00
|
|
|
assert.NoError(t, f.SetSheetPrOptions("Sheet1", TabColor("")))
|
2019-10-16 01:03:29 +08:00
|
|
|
// Test SetSheetrOptions on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetSheetPrOptions("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSheetPrOptions(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
// Test GetSheetPrOptions on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.GetSheetPrOptions("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
var _ = []PageMarginsOptions{
|
|
|
|
PageMarginBottom(1.0),
|
|
|
|
PageMarginFooter(1.0),
|
|
|
|
PageMarginHeader(1.0),
|
|
|
|
PageMarginLeft(1.0),
|
|
|
|
PageMarginRight(1.0),
|
|
|
|
PageMarginTop(1.0),
|
2019-10-16 01:03:29 +08:00
|
|
|
}
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
var _ = []PageMarginsOptionsPtr{
|
|
|
|
(*PageMarginBottom)(nil),
|
|
|
|
(*PageMarginFooter)(nil),
|
|
|
|
(*PageMarginHeader)(nil),
|
|
|
|
(*PageMarginLeft)(nil),
|
|
|
|
(*PageMarginRight)(nil),
|
|
|
|
(*PageMarginTop)(nil),
|
2019-10-16 01:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_SetPageMargins() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
if err := f.SetPageMargins(sheet,
|
2020-10-04 21:07:39 +08:00
|
|
|
PageMarginBottom(1.0),
|
|
|
|
PageMarginFooter(1.0),
|
|
|
|
PageMarginHeader(1.0),
|
|
|
|
PageMarginLeft(1.0),
|
|
|
|
PageMarginRight(1.0),
|
|
|
|
PageMarginTop(1.0),
|
2019-10-16 01:03:29 +08:00
|
|
|
); err != nil {
|
2020-02-19 00:08:10 +08:00
|
|
|
fmt.Println(err)
|
2019-10-16 01:03:29 +08:00
|
|
|
}
|
|
|
|
// Output:
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_GetPageMargins() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
var (
|
2020-10-04 21:07:39 +08:00
|
|
|
marginBottom PageMarginBottom
|
|
|
|
marginFooter PageMarginFooter
|
|
|
|
marginHeader PageMarginHeader
|
|
|
|
marginLeft PageMarginLeft
|
|
|
|
marginRight PageMarginRight
|
|
|
|
marginTop PageMarginTop
|
2019-10-16 01:03:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if err := f.GetPageMargins(sheet,
|
|
|
|
&marginBottom,
|
|
|
|
&marginFooter,
|
|
|
|
&marginHeader,
|
|
|
|
&marginLeft,
|
|
|
|
&marginRight,
|
|
|
|
&marginTop,
|
|
|
|
); err != nil {
|
2020-02-19 00:08:10 +08:00
|
|
|
fmt.Println(err)
|
2019-10-16 01:03:29 +08:00
|
|
|
}
|
|
|
|
fmt.Println("Defaults:")
|
|
|
|
fmt.Println("- marginBottom:", marginBottom)
|
|
|
|
fmt.Println("- marginFooter:", marginFooter)
|
|
|
|
fmt.Println("- marginHeader:", marginHeader)
|
|
|
|
fmt.Println("- marginLeft:", marginLeft)
|
|
|
|
fmt.Println("- marginRight:", marginRight)
|
|
|
|
fmt.Println("- marginTop:", marginTop)
|
|
|
|
// Output:
|
|
|
|
// Defaults:
|
|
|
|
// - marginBottom: 0.75
|
|
|
|
// - marginFooter: 0.3
|
|
|
|
// - marginHeader: 0.3
|
|
|
|
// - marginLeft: 0.7
|
|
|
|
// - marginRight: 0.7
|
|
|
|
// - marginTop: 0.75
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPageMarginsOption(t *testing.T) {
|
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
testData := []struct {
|
2020-10-04 21:07:39 +08:00
|
|
|
container PageMarginsOptionsPtr
|
|
|
|
nonDefault PageMarginsOptions
|
2019-10-16 01:03:29 +08:00
|
|
|
}{
|
2020-10-04 21:07:39 +08:00
|
|
|
{new(PageMarginTop), PageMarginTop(1.0)},
|
|
|
|
{new(PageMarginBottom), PageMarginBottom(1.0)},
|
|
|
|
{new(PageMarginLeft), PageMarginLeft(1.0)},
|
|
|
|
{new(PageMarginRight), PageMarginRight(1.0)},
|
|
|
|
{new(PageMarginHeader), PageMarginHeader(1.0)},
|
|
|
|
{new(PageMarginFooter), PageMarginFooter(1.0)},
|
2019-10-16 01:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range testData {
|
|
|
|
t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {
|
|
|
|
|
|
|
|
opt := test.nonDefault
|
|
|
|
t.Logf("option %T", opt)
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
def := deepcopy.Copy(test.container).(PageMarginsOptionsPtr)
|
|
|
|
val1 := deepcopy.Copy(def).(PageMarginsOptionsPtr)
|
|
|
|
val2 := deepcopy.Copy(def).(PageMarginsOptionsPtr)
|
2019-10-16 01:03:29 +08:00
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
// Get the default value
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, def), opt)
|
|
|
|
// Get again and check
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, val1, def, opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set the same value
|
|
|
|
assert.NoError(t, f.SetPageMargins(sheet, val1), opt)
|
|
|
|
// Get again and check
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set a different value
|
|
|
|
assert.NoError(t, f.SetPageMargins(sheet, test.nonDefault), opt)
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, val1), opt)
|
|
|
|
// Get again and compare
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, val2), opt)
|
|
|
|
if !assert.Equal(t, val1, val2, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Value should not be the same as the default
|
|
|
|
if !assert.NotEqual(t, def, val1, "%T: value should have changed from default", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Restore the default value
|
|
|
|
assert.NoError(t, f.SetPageMargins(sheet, def), opt)
|
|
|
|
assert.NoError(t, f.GetPageMargins(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, def, val1) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetPageMargins(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
// Test set page margins on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetPageMargins("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPageMargins(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2019-10-16 01:03:29 +08:00
|
|
|
// Test get page margins on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.GetPageMargins("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|
2020-05-12 23:26:26 +08:00
|
|
|
|
|
|
|
func ExampleFile_SetSheetFormatPr() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2020-05-12 23:26:26 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
if err := f.SetSheetFormatPr(sheet,
|
2020-10-04 21:07:39 +08:00
|
|
|
BaseColWidth(1.0),
|
|
|
|
DefaultColWidth(1.0),
|
|
|
|
DefaultRowHeight(1.0),
|
|
|
|
CustomHeight(true),
|
|
|
|
ZeroHeight(true),
|
|
|
|
ThickTop(true),
|
|
|
|
ThickBottom(true),
|
2020-05-12 23:26:26 +08:00
|
|
|
); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
// Output:
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_GetSheetFormatPr() {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2020-05-12 23:26:26 +08:00
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
var (
|
2020-10-04 21:07:39 +08:00
|
|
|
baseColWidth BaseColWidth
|
|
|
|
defaultColWidth DefaultColWidth
|
|
|
|
defaultRowHeight DefaultRowHeight
|
|
|
|
customHeight CustomHeight
|
|
|
|
zeroHeight ZeroHeight
|
|
|
|
thickTop ThickTop
|
|
|
|
thickBottom ThickBottom
|
2020-05-12 23:26:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if err := f.GetSheetFormatPr(sheet,
|
|
|
|
&baseColWidth,
|
|
|
|
&defaultColWidth,
|
|
|
|
&defaultRowHeight,
|
|
|
|
&customHeight,
|
|
|
|
&zeroHeight,
|
|
|
|
&thickTop,
|
|
|
|
&thickBottom,
|
|
|
|
); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Defaults:")
|
|
|
|
fmt.Println("- baseColWidth:", baseColWidth)
|
|
|
|
fmt.Println("- defaultColWidth:", defaultColWidth)
|
|
|
|
fmt.Println("- defaultRowHeight:", defaultRowHeight)
|
|
|
|
fmt.Println("- customHeight:", customHeight)
|
|
|
|
fmt.Println("- zeroHeight:", zeroHeight)
|
|
|
|
fmt.Println("- thickTop:", thickTop)
|
|
|
|
fmt.Println("- thickBottom:", thickBottom)
|
|
|
|
// Output:
|
|
|
|
// Defaults:
|
|
|
|
// - baseColWidth: 0
|
|
|
|
// - defaultColWidth: 0
|
|
|
|
// - defaultRowHeight: 15
|
|
|
|
// - customHeight: false
|
|
|
|
// - zeroHeight: false
|
|
|
|
// - thickTop: false
|
|
|
|
// - thickBottom: false
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSheetFormatPrOptions(t *testing.T) {
|
|
|
|
const sheet = "Sheet1"
|
|
|
|
|
|
|
|
testData := []struct {
|
2020-10-04 21:07:39 +08:00
|
|
|
container SheetFormatPrOptionsPtr
|
|
|
|
nonDefault SheetFormatPrOptions
|
2020-05-12 23:26:26 +08:00
|
|
|
}{
|
2020-10-04 21:07:39 +08:00
|
|
|
{new(BaseColWidth), BaseColWidth(1.0)},
|
|
|
|
{new(DefaultColWidth), DefaultColWidth(1.0)},
|
|
|
|
{new(DefaultRowHeight), DefaultRowHeight(1.0)},
|
|
|
|
{new(CustomHeight), CustomHeight(true)},
|
|
|
|
{new(ZeroHeight), ZeroHeight(true)},
|
|
|
|
{new(ThickTop), ThickTop(true)},
|
|
|
|
{new(ThickBottom), ThickBottom(true)},
|
2020-05-12 23:26:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range testData {
|
|
|
|
t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {
|
|
|
|
|
|
|
|
opt := test.nonDefault
|
|
|
|
t.Logf("option %T", opt)
|
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
def := deepcopy.Copy(test.container).(SheetFormatPrOptionsPtr)
|
|
|
|
val1 := deepcopy.Copy(def).(SheetFormatPrOptionsPtr)
|
|
|
|
val2 := deepcopy.Copy(def).(SheetFormatPrOptionsPtr)
|
2020-05-12 23:26:26 +08:00
|
|
|
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2020-05-12 23:26:26 +08:00
|
|
|
// Get the default value
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, def), opt)
|
|
|
|
// Get again and check
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, val1, def, opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set the same value
|
|
|
|
assert.NoError(t, f.SetSheetFormatPr(sheet, val1), opt)
|
|
|
|
// Get again and check
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Set a different value
|
|
|
|
assert.NoError(t, f.SetSheetFormatPr(sheet, test.nonDefault), opt)
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, val1), opt)
|
|
|
|
// Get again and compare
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, val2), opt)
|
|
|
|
if !assert.Equal(t, val1, val2, "%T: value should not have changed", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Value should not be the same as the default
|
|
|
|
if !assert.NotEqual(t, def, val1, "%T: value should have changed from default", opt) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Restore the default value
|
|
|
|
assert.NoError(t, f.SetSheetFormatPr(sheet, def), opt)
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr(sheet, val1), opt)
|
|
|
|
if !assert.Equal(t, def, val1) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetSheetFormatPr(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2020-05-12 23:26:26 +08:00
|
|
|
assert.NoError(t, f.GetSheetFormatPr("Sheet1"))
|
|
|
|
f.Sheet["xl/worksheets/sheet1.xml"].SheetFormatPr = nil
|
2020-10-04 21:07:39 +08:00
|
|
|
assert.NoError(t, f.SetSheetFormatPr("Sheet1", BaseColWidth(1.0)))
|
2020-05-12 23:26:26 +08:00
|
|
|
// Test set formatting properties on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetSheetFormatPr("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSheetFormatPr(t *testing.T) {
|
2020-10-04 21:07:39 +08:00
|
|
|
f := NewFile()
|
2020-05-12 23:26:26 +08:00
|
|
|
assert.NoError(t, f.GetSheetFormatPr("Sheet1"))
|
|
|
|
f.Sheet["xl/worksheets/sheet1.xml"].SheetFormatPr = nil
|
|
|
|
var (
|
2020-10-04 21:07:39 +08:00
|
|
|
baseColWidth BaseColWidth
|
|
|
|
defaultColWidth DefaultColWidth
|
|
|
|
defaultRowHeight DefaultRowHeight
|
|
|
|
customHeight CustomHeight
|
|
|
|
zeroHeight ZeroHeight
|
|
|
|
thickTop ThickTop
|
|
|
|
thickBottom ThickBottom
|
2020-05-12 23:26:26 +08:00
|
|
|
)
|
|
|
|
assert.NoError(t, f.GetSheetFormatPr("Sheet1",
|
|
|
|
&baseColWidth,
|
|
|
|
&defaultColWidth,
|
|
|
|
&defaultRowHeight,
|
|
|
|
&customHeight,
|
|
|
|
&zeroHeight,
|
|
|
|
&thickTop,
|
|
|
|
&thickBottom,
|
|
|
|
))
|
|
|
|
// Test get formatting properties on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.GetSheetFormatPr("SheetN"), "sheet SheetN is not exist")
|
|
|
|
}
|