This closes #1283, support set and get color index, theme and tint for sheet tab
This commit renames `TabColor` into `TabColorRGB` (but keeps an alias for backwards compatibility), as well as adds support for more tab color options (Theme, Indexed and Tint). Signed-off-by: Thomas Charbonnel <github@charbonnel.email>
This commit is contained in:
parent
ebea684ae5
commit
fd0eb2bcbf
90
sheetpr.go
90
sheetpr.go
|
@ -33,14 +33,37 @@ type (
|
||||||
Published bool
|
Published bool
|
||||||
// FitToPage is a SheetPrOption
|
// FitToPage is a SheetPrOption
|
||||||
FitToPage bool
|
FitToPage bool
|
||||||
// TabColor is a SheetPrOption
|
// TabColorIndexed is a TabColor option, within SheetPrOption
|
||||||
TabColor string
|
TabColorIndexed int
|
||||||
|
// TabColorRGB is a TabColor option, within SheetPrOption
|
||||||
|
TabColorRGB string
|
||||||
|
// TabColorTheme is a TabColor option, within SheetPrOption
|
||||||
|
TabColorTheme int
|
||||||
|
// TabColorTint is a TabColor option, within SheetPrOption
|
||||||
|
TabColorTint float64
|
||||||
// AutoPageBreaks is a SheetPrOption
|
// AutoPageBreaks is a SheetPrOption
|
||||||
AutoPageBreaks bool
|
AutoPageBreaks bool
|
||||||
// OutlineSummaryBelow is an outlinePr, within SheetPr option
|
// OutlineSummaryBelow is an outlinePr, within SheetPr option
|
||||||
OutlineSummaryBelow bool
|
OutlineSummaryBelow bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TabColorThemeLight1 int = iota // Inverted compared to the spec because that's how Excel maps them
|
||||||
|
TabColorThemeDark1
|
||||||
|
TabColorThemeLight2
|
||||||
|
TabColorThemeDark2
|
||||||
|
TabColorThemeAccent1
|
||||||
|
TabColorThemeAccent2
|
||||||
|
TabColorThemeAccent3
|
||||||
|
TabColorThemeAccent4
|
||||||
|
TabColorThemeAccent5
|
||||||
|
TabColorThemeAccent6
|
||||||
|
TabColorThemeHyperlink
|
||||||
|
TabColorThemeFollowedHyperlink
|
||||||
|
|
||||||
|
TabColorUnsetValue int = -1
|
||||||
|
)
|
||||||
|
|
||||||
// setSheetPrOption implements the SheetPrOption interface.
|
// setSheetPrOption implements the SheetPrOption interface.
|
||||||
func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) {
|
func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
if pr.OutlinePr == nil {
|
if pr.OutlinePr == nil {
|
||||||
|
@ -129,9 +152,28 @@ func (o *FitToPage) getSheetPrOption(pr *xlsxSheetPr) {
|
||||||
*o = FitToPage(pr.PageSetUpPr.FitToPage)
|
*o = FitToPage(pr.PageSetUpPr.FitToPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setSheetPrOption implements the SheetPrOption interface and sets the
|
||||||
|
// TabColor Indexed.
|
||||||
|
func (o TabColorIndexed) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr.TabColor == nil {
|
||||||
|
pr.TabColor = new(xlsxTabColor)
|
||||||
|
}
|
||||||
|
pr.TabColor.Indexed = int(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getSheetPrOption implements the SheetPrOptionPtr interface and gets the
|
||||||
|
// TabColor Indexed. Defaults to -1 if no indexed has been set.
|
||||||
|
func (o *TabColorIndexed) getSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr == nil || pr.TabColor == nil {
|
||||||
|
*o = TabColorIndexed(TabColorUnsetValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*o = TabColorIndexed(pr.TabColor.Indexed)
|
||||||
|
}
|
||||||
|
|
||||||
// setSheetPrOption implements the SheetPrOption interface and specifies a
|
// setSheetPrOption implements the SheetPrOption interface and specifies a
|
||||||
// stable name of the sheet.
|
// stable name of the sheet.
|
||||||
func (o TabColor) setSheetPrOption(pr *xlsxSheetPr) {
|
func (o TabColorRGB) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
if pr.TabColor == nil {
|
if pr.TabColor == nil {
|
||||||
if string(o) == "" {
|
if string(o) == "" {
|
||||||
return
|
return
|
||||||
|
@ -143,12 +185,50 @@ func (o TabColor) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
|
||||||
// getSheetPrOption implements the SheetPrOptionPtr interface and get the
|
// getSheetPrOption implements the SheetPrOptionPtr interface and get the
|
||||||
// stable name of the sheet.
|
// stable name of the sheet.
|
||||||
func (o *TabColor) getSheetPrOption(pr *xlsxSheetPr) {
|
func (o *TabColorRGB) getSheetPrOption(pr *xlsxSheetPr) {
|
||||||
if pr == nil || pr.TabColor == nil {
|
if pr == nil || pr.TabColor == nil {
|
||||||
*o = ""
|
*o = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*o = TabColor(strings.TrimPrefix(pr.TabColor.RGB, "FF"))
|
*o = TabColorRGB(strings.TrimPrefix(pr.TabColor.RGB, "FF"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// setSheetPrOption implements the SheetPrOption interface and sets the
|
||||||
|
// TabColor Theme. Warning: it does not create a clrScheme!
|
||||||
|
func (o TabColorTheme) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr.TabColor == nil {
|
||||||
|
pr.TabColor = new(xlsxTabColor)
|
||||||
|
}
|
||||||
|
pr.TabColor.Theme = int(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getSheetPrOption implements the SheetPrOptionPtr interface and gets the
|
||||||
|
// TabColor Theme. Defaults to -1 if no theme has been set.
|
||||||
|
func (o *TabColorTheme) getSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr == nil || pr.TabColor == nil {
|
||||||
|
*o = TabColorTheme(TabColorUnsetValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*o = TabColorTheme(pr.TabColor.Theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setSheetPrOption implements the SheetPrOption interface and sets the
|
||||||
|
// TabColor Tint.
|
||||||
|
func (o TabColorTint) setSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr.TabColor == nil {
|
||||||
|
pr.TabColor = new(xlsxTabColor)
|
||||||
|
}
|
||||||
|
pr.TabColor.Tint = float64(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getSheetPrOption implements the SheetPrOptionPtr interface and gets the
|
||||||
|
// TabColor Tint. Defaults to 0.0 if no tint has been set.
|
||||||
|
func (o *TabColorTint) getSheetPrOption(pr *xlsxSheetPr) {
|
||||||
|
if pr == nil || pr.TabColor == nil {
|
||||||
|
*o = 0.0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*o = TabColorTint(pr.TabColor.Tint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setSheetPrOption implements the SheetPrOption interface.
|
// setSheetPrOption implements the SheetPrOption interface.
|
||||||
|
|
|
@ -13,7 +13,10 @@ var _ = []SheetPrOption{
|
||||||
EnableFormatConditionsCalculation(false),
|
EnableFormatConditionsCalculation(false),
|
||||||
Published(false),
|
Published(false),
|
||||||
FitToPage(true),
|
FitToPage(true),
|
||||||
TabColor("#FFFF00"),
|
TabColorIndexed(42),
|
||||||
|
TabColorRGB("#FFFF00"),
|
||||||
|
TabColorTheme(TabColorThemeLight2),
|
||||||
|
TabColorTint(0.5),
|
||||||
AutoPageBreaks(true),
|
AutoPageBreaks(true),
|
||||||
OutlineSummaryBelow(true),
|
OutlineSummaryBelow(true),
|
||||||
}
|
}
|
||||||
|
@ -23,7 +26,10 @@ var _ = []SheetPrOptionPtr{
|
||||||
(*EnableFormatConditionsCalculation)(nil),
|
(*EnableFormatConditionsCalculation)(nil),
|
||||||
(*Published)(nil),
|
(*Published)(nil),
|
||||||
(*FitToPage)(nil),
|
(*FitToPage)(nil),
|
||||||
(*TabColor)(nil),
|
(*TabColorIndexed)(nil),
|
||||||
|
(*TabColorRGB)(nil),
|
||||||
|
(*TabColorTheme)(nil),
|
||||||
|
(*TabColorTint)(nil),
|
||||||
(*AutoPageBreaks)(nil),
|
(*AutoPageBreaks)(nil),
|
||||||
(*OutlineSummaryBelow)(nil),
|
(*OutlineSummaryBelow)(nil),
|
||||||
}
|
}
|
||||||
|
@ -37,7 +43,10 @@ func ExampleFile_SetSheetPrOptions() {
|
||||||
EnableFormatConditionsCalculation(false),
|
EnableFormatConditionsCalculation(false),
|
||||||
Published(false),
|
Published(false),
|
||||||
FitToPage(true),
|
FitToPage(true),
|
||||||
TabColor("#FFFF00"),
|
TabColorIndexed(42),
|
||||||
|
TabColorRGB("#FFFF00"),
|
||||||
|
TabColorTheme(TabColorThemeLight2),
|
||||||
|
TabColorTint(0.5),
|
||||||
AutoPageBreaks(true),
|
AutoPageBreaks(true),
|
||||||
OutlineSummaryBelow(false),
|
OutlineSummaryBelow(false),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -55,7 +64,10 @@ func ExampleFile_GetSheetPrOptions() {
|
||||||
enableFormatConditionsCalculation EnableFormatConditionsCalculation
|
enableFormatConditionsCalculation EnableFormatConditionsCalculation
|
||||||
published Published
|
published Published
|
||||||
fitToPage FitToPage
|
fitToPage FitToPage
|
||||||
tabColor TabColor
|
tabColorIndexed TabColorIndexed
|
||||||
|
tabColorRGB TabColorRGB
|
||||||
|
tabColorTheme TabColorTheme
|
||||||
|
tabColorTint TabColorTint
|
||||||
autoPageBreaks AutoPageBreaks
|
autoPageBreaks AutoPageBreaks
|
||||||
outlineSummaryBelow OutlineSummaryBelow
|
outlineSummaryBelow OutlineSummaryBelow
|
||||||
)
|
)
|
||||||
|
@ -65,7 +77,10 @@ func ExampleFile_GetSheetPrOptions() {
|
||||||
&enableFormatConditionsCalculation,
|
&enableFormatConditionsCalculation,
|
||||||
&published,
|
&published,
|
||||||
&fitToPage,
|
&fitToPage,
|
||||||
&tabColor,
|
&tabColorIndexed,
|
||||||
|
&tabColorRGB,
|
||||||
|
&tabColorTheme,
|
||||||
|
&tabColorTint,
|
||||||
&autoPageBreaks,
|
&autoPageBreaks,
|
||||||
&outlineSummaryBelow,
|
&outlineSummaryBelow,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -76,7 +91,10 @@ func ExampleFile_GetSheetPrOptions() {
|
||||||
fmt.Println("- enableFormatConditionsCalculation:", enableFormatConditionsCalculation)
|
fmt.Println("- enableFormatConditionsCalculation:", enableFormatConditionsCalculation)
|
||||||
fmt.Println("- published:", published)
|
fmt.Println("- published:", published)
|
||||||
fmt.Println("- fitToPage:", fitToPage)
|
fmt.Println("- fitToPage:", fitToPage)
|
||||||
fmt.Printf("- tabColor: %q\n", tabColor)
|
fmt.Printf("- tabColorIndexed: %d\n", tabColorIndexed)
|
||||||
|
fmt.Printf("- tabColorRGB: %q\n", tabColorRGB)
|
||||||
|
fmt.Printf("- tabColorTheme: %d\n", tabColorTheme)
|
||||||
|
fmt.Printf("- tabColorTint: %f\n", tabColorTint)
|
||||||
fmt.Println("- autoPageBreaks:", autoPageBreaks)
|
fmt.Println("- autoPageBreaks:", autoPageBreaks)
|
||||||
fmt.Println("- outlineSummaryBelow:", outlineSummaryBelow)
|
fmt.Println("- outlineSummaryBelow:", outlineSummaryBelow)
|
||||||
// Output:
|
// Output:
|
||||||
|
@ -85,7 +103,10 @@ func ExampleFile_GetSheetPrOptions() {
|
||||||
// - enableFormatConditionsCalculation: true
|
// - enableFormatConditionsCalculation: true
|
||||||
// - published: true
|
// - published: true
|
||||||
// - fitToPage: false
|
// - fitToPage: false
|
||||||
// - tabColor: ""
|
// - tabColorIndexed: -1
|
||||||
|
// - tabColorRGB: ""
|
||||||
|
// - tabColorTheme: -1
|
||||||
|
// - tabColorTint: 0.000000
|
||||||
// - autoPageBreaks: false
|
// - autoPageBreaks: false
|
||||||
// - outlineSummaryBelow: true
|
// - outlineSummaryBelow: true
|
||||||
}
|
}
|
||||||
|
@ -101,7 +122,10 @@ func TestSheetPrOptions(t *testing.T) {
|
||||||
{new(EnableFormatConditionsCalculation), EnableFormatConditionsCalculation(false)},
|
{new(EnableFormatConditionsCalculation), EnableFormatConditionsCalculation(false)},
|
||||||
{new(Published), Published(false)},
|
{new(Published), Published(false)},
|
||||||
{new(FitToPage), FitToPage(true)},
|
{new(FitToPage), FitToPage(true)},
|
||||||
{new(TabColor), TabColor("FFFF00")},
|
{new(TabColorIndexed), TabColorIndexed(42)},
|
||||||
|
{new(TabColorRGB), TabColorRGB("FFFF00")},
|
||||||
|
{new(TabColorTheme), TabColorTheme(TabColorThemeLight2)},
|
||||||
|
{new(TabColorTint), TabColorTint(0.5)},
|
||||||
{new(AutoPageBreaks), AutoPageBreaks(true)},
|
{new(AutoPageBreaks), AutoPageBreaks(true)},
|
||||||
{new(OutlineSummaryBelow), OutlineSummaryBelow(false)},
|
{new(OutlineSummaryBelow), OutlineSummaryBelow(false)},
|
||||||
}
|
}
|
||||||
|
@ -154,7 +178,7 @@ func TestSheetPrOptions(t *testing.T) {
|
||||||
|
|
||||||
func TestSetSheetPrOptions(t *testing.T) {
|
func TestSetSheetPrOptions(t *testing.T) {
|
||||||
f := NewFile()
|
f := NewFile()
|
||||||
assert.NoError(t, f.SetSheetPrOptions("Sheet1", TabColor("")))
|
assert.NoError(t, f.SetSheetPrOptions("Sheet1", TabColorRGB("")))
|
||||||
// Test SetSheetPrOptions on not exists worksheet.
|
// Test SetSheetPrOptions on not exists worksheet.
|
||||||
assert.EqualError(t, f.SetSheetPrOptions("SheetN"), "sheet SheetN is not exist")
|
assert.EqualError(t, f.SetSheetPrOptions("SheetN"), "sheet SheetN is not exist")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue