summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sheet.go20
-rw-r--r--sheet_test.go9
-rw-r--r--xmlWorksheet.go2
3 files changed, 29 insertions, 2 deletions
diff --git a/sheet.go b/sheet.go
index 82c6a69..9f71de4 100644
--- a/sheet.go
+++ b/sheet.go
@@ -1144,6 +1144,10 @@ type (
FitToHeight int
// FitToWidth specified number of horizontal pages to fit on
FitToWidth int
+ // PageLayoutScale defines the print scaling. This attribute is restricted
+ // to values ranging from 10 (10%) to 400 (400%). This setting is
+ // overridden when fitToWidth and/or fitToHeight are in use.
+ PageLayoutScale uint
)
const (
@@ -1215,6 +1219,22 @@ func (p *FitToWidth) getPageLayout(ps *xlsxPageSetUp) {
*p = FitToWidth(ps.FitToWidth)
}
+// setPageLayout provides a method to set the scale for the worksheet.
+func (p PageLayoutScale) setPageLayout(ps *xlsxPageSetUp) {
+ if 10 <= uint(p) && uint(p) <= 400 {
+ ps.Scale = uint(p)
+ }
+}
+
+// getPageLayout provides a method to get the scale for the worksheet.
+func (p *PageLayoutScale) getPageLayout(ps *xlsxPageSetUp) {
+ if ps == nil || ps.Scale < 10 || ps.Scale > 400 {
+ *p = 100
+ return
+ }
+ *p = PageLayoutScale(ps.Scale)
+}
+
// SetPageLayout provides a function to sets worksheet page layout.
//
// Available options:
diff --git a/sheet_test.go b/sheet_test.go
index d1c8f64..701d824 100644
--- a/sheet_test.go
+++ b/sheet_test.go
@@ -25,6 +25,7 @@ func ExampleFile_SetPageLayout() {
PageLayoutPaperSize(10),
FitToHeight(2),
FitToWidth(2),
+ PageLayoutScale(50),
); err != nil {
fmt.Println(err)
}
@@ -38,6 +39,7 @@ func ExampleFile_GetPageLayout() {
paperSize PageLayoutPaperSize
fitToHeight FitToHeight
fitToWidth FitToWidth
+ scale PageLayoutScale
)
if err := f.GetPageLayout("Sheet1", &orientation); err != nil {
fmt.Println(err)
@@ -48,21 +50,25 @@ func ExampleFile_GetPageLayout() {
if err := f.GetPageLayout("Sheet1", &fitToHeight); err != nil {
fmt.Println(err)
}
-
if err := f.GetPageLayout("Sheet1", &fitToWidth); err != nil {
fmt.Println(err)
}
+ if err := f.GetPageLayout("Sheet1", &scale); err != nil {
+ fmt.Println(err)
+ }
fmt.Println("Defaults:")
fmt.Printf("- orientation: %q\n", orientation)
fmt.Printf("- paper size: %d\n", paperSize)
fmt.Printf("- fit to height: %d\n", fitToHeight)
fmt.Printf("- fit to width: %d\n", fitToWidth)
+ fmt.Printf("- scale: %d\n", scale)
// Output:
// Defaults:
// - orientation: "portrait"
// - paper size: 1
// - fit to height: 1
// - fit to width: 1
+ // - scale: 100
}
func TestNewSheet(t *testing.T) {
@@ -101,6 +107,7 @@ func TestPageLayoutOption(t *testing.T) {
{new(PageLayoutPaperSize), PageLayoutPaperSize(10)},
{new(FitToHeight), FitToHeight(2)},
{new(FitToWidth), FitToWidth(2)},
+ {new(PageLayoutScale), PageLayoutScale(50)},
}
for i, test := range testData {
diff --git a/xmlWorksheet.go b/xmlWorksheet.go
index 26c8fac..1f680d2 100644
--- a/xmlWorksheet.go
+++ b/xmlWorksheet.go
@@ -121,7 +121,7 @@ type xlsxPageSetUp struct {
PaperHeight string `xml:"paperHeight,attr,omitempty"`
PaperSize int `xml:"paperSize,attr,omitempty"`
PaperWidth string `xml:"paperWidth,attr,omitempty"`
- Scale int `xml:"scale,attr,omitempty"`
+ Scale uint `xml:"scale,attr,omitempty"`
UseFirstPageNumber bool `xml:"useFirstPageNumber,attr,omitempty"`
UsePrinterDefaults bool `xml:"usePrinterDefaults,attr,omitempty"`
VerticalDPI int `xml:"verticalDpi,attr,omitempty"`