summaryrefslogtreecommitdiff
path: root/sheetpr.go
diff options
context:
space:
mode:
authorThomas Charbonnel <thomascharbonnel@users.noreply.github.com>2022-07-26 12:36:21 +0800
committerGitHub <noreply@github.com>2022-07-26 12:36:21 +0800
commitfd0eb2bcbf31eccfc2b853dc406e0cfd247f7fb2 (patch)
treec49eb078121b9a8bf62eca715c0df12ea0d80544 /sheetpr.go
parentebea684ae5c60776d4d8364b7360d0c0603cb3b0 (diff)
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>
Diffstat (limited to 'sheetpr.go')
-rw-r--r--sheetpr.go90
1 files changed, 85 insertions, 5 deletions
diff --git a/sheetpr.go b/sheetpr.go
index 73fb5b0..cc4e4a9 100644
--- a/sheetpr.go
+++ b/sheetpr.go
@@ -33,14 +33,37 @@ type (
Published bool
// FitToPage is a SheetPrOption
FitToPage bool
- // TabColor is a SheetPrOption
- TabColor string
+ // TabColorIndexed is a TabColor option, within SheetPrOption
+ 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 bool
// OutlineSummaryBelow is an outlinePr, within SheetPr option
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.
func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) {
if pr.OutlinePr == nil {
@@ -129,9 +152,28 @@ func (o *FitToPage) getSheetPrOption(pr *xlsxSheetPr) {
*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
// stable name of the sheet.
-func (o TabColor) setSheetPrOption(pr *xlsxSheetPr) {
+func (o TabColorRGB) setSheetPrOption(pr *xlsxSheetPr) {
if pr.TabColor == nil {
if string(o) == "" {
return
@@ -143,12 +185,50 @@ func (o TabColor) setSheetPrOption(pr *xlsxSheetPr) {
// getSheetPrOption implements the SheetPrOptionPtr interface and get the
// stable name of the sheet.
-func (o *TabColor) getSheetPrOption(pr *xlsxSheetPr) {
+func (o *TabColorRGB) getSheetPrOption(pr *xlsxSheetPr) {
if pr == nil || pr.TabColor == nil {
*o = ""
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.