Resolve #432, supplement the function of SetPageLayout

SetPageLayout support to set fit to width and height
This commit is contained in:
xuri 2019-07-06 15:11:51 +08:00 committed by GitHub
parent 4897276c68
commit e14d2febc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 0 deletions

View File

@ -1025,6 +1025,10 @@ type (
PageLayoutOrientation string
// PageLayoutPaperSize defines the paper size of the worksheet
PageLayoutPaperSize int
// FitToHeight specified number of vertical pages to fit on
FitToHeight int
// FitToWidth specified number of horizontal pages to fit on
FitToWidth int
)
const (
@ -1064,6 +1068,38 @@ func (p *PageLayoutPaperSize) getPageLayout(ps *xlsxPageSetUp) {
*p = PageLayoutPaperSize(ps.PaperSize)
}
// setPageLayout provides a method to set the fit to height for the worksheet.
func (p FitToHeight) setPageLayout(ps *xlsxPageSetUp) {
if int(p) > 0 {
ps.FitToHeight = int(p)
}
}
// getPageLayout provides a method to get the fit to height for the worksheet.
func (p *FitToHeight) getPageLayout(ps *xlsxPageSetUp) {
if ps == nil || ps.FitToHeight == 0 {
*p = 1
return
}
*p = FitToHeight(ps.FitToHeight)
}
// setPageLayout provides a method to set the fit to width for the worksheet.
func (p FitToWidth) setPageLayout(ps *xlsxPageSetUp) {
if int(p) > 0 {
ps.FitToWidth = int(p)
}
}
// getPageLayout provides a method to get the fit to width for the worksheet.
func (p *FitToWidth) getPageLayout(ps *xlsxPageSetUp) {
if ps == nil || ps.FitToWidth == 0 {
*p = 1
return
}
*p = FitToWidth(ps.FitToWidth)
}
// SetPageLayout provides a function to sets worksheet page layout.
//
// Available options:
@ -1213,6 +1249,8 @@ func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error {
// Available options:
// PageLayoutOrientation(string)
// PageLayoutPaperSize(int)
// FitToHeight(int)
// FitToWidth(int)
func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error {
s, err := f.workSheetReader(sheet)
if err != nil {