Improvement compatibility with invalid first-page number attribute in the page layout

This commit is contained in:
xuri 2021-07-21 23:24:49 +08:00
parent 1ec0207fb5
commit 5ce3fe8cb8
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 8 additions and 6 deletions

View File

@ -1202,7 +1202,7 @@ func (p *BlackAndWhite) getPageLayout(ps *xlsxPageSetUp) {
// the worksheet.
func (p FirstPageNumber) setPageLayout(ps *xlsxPageSetUp) {
if 0 < int(p) {
ps.FirstPageNumber = int(p)
ps.FirstPageNumber = strconv.Itoa(int(p))
ps.UseFirstPageNumber = true
}
}
@ -1210,11 +1210,13 @@ func (p FirstPageNumber) setPageLayout(ps *xlsxPageSetUp) {
// getPageLayout provides a method to get the first printed page number for
// the worksheet.
func (p *FirstPageNumber) getPageLayout(ps *xlsxPageSetUp) {
if ps == nil || ps.FirstPageNumber == 0 || !ps.UseFirstPageNumber {
*p = 1
return
if ps != nil && ps.UseFirstPageNumber {
if number, _ := strconv.Atoi(ps.FirstPageNumber); number != 0 {
*p = FirstPageNumber(number)
return
}
}
*p = FirstPageNumber(ps.FirstPageNumber)
*p = 1
}
// setPageLayout provides a method to set the orientation for the worksheet.

View File

@ -111,7 +111,7 @@ type xlsxPageSetUp struct {
Copies int `xml:"copies,attr,omitempty"`
Draft bool `xml:"draft,attr,omitempty"`
Errors string `xml:"errors,attr,omitempty"`
FirstPageNumber int `xml:"firstPageNumber,attr,omitempty"`
FirstPageNumber string `xml:"firstPageNumber,attr,omitempty"`
FitToHeight int `xml:"fitToHeight,attr,omitempty"`
FitToWidth int `xml:"fitToWidth,attr,omitempty"`
HorizontalDPI int `xml:"horizontalDpi,attr,omitempty"`