Skip to content

Commit

Permalink
Simplify code for the setPageSetUp function to reduce cyclomatic comp…
Browse files Browse the repository at this point in the history
…lexity
  • Loading branch information
xuri committed Nov 8, 2024
1 parent 9ab6b22 commit f2e39c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ func (ws *xlsxWorksheet) setPageSetUp(opts *PageLayoutOptions) {
ws.newPageSetUp()
ws.PageSetUp.PaperSize = opts.Size
}
if opts.Orientation != nil && (*opts.Orientation == "portrait" || *opts.Orientation == "landscape") {
if opts.Orientation != nil && inStrSlice(supportedPageOrientation, *opts.Orientation, true) != -1 {
ws.newPageSetUp()
ws.PageSetUp.Orientation = *opts.Orientation
}
Expand All @@ -1652,7 +1652,7 @@ func (ws *xlsxWorksheet) setPageSetUp(opts *PageLayoutOptions) {
ws.newPageSetUp()
ws.PageSetUp.BlackAndWhite = *opts.BlackAndWhite
}
if opts.PageOrder != nil && (*opts.PageOrder == "overThenDown" || *opts.PageOrder == "downThenOver") {
if opts.PageOrder != nil && inStrSlice(supportedPageOrder, *opts.PageOrder, true) != -1 {
ws.newPageSetUp()
ws.PageSetUp.PageOrder = *opts.PageOrder
}
Expand All @@ -1662,7 +1662,7 @@ func (ws *xlsxWorksheet) setPageSetUp(opts *PageLayoutOptions) {
func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error) {
opts := PageLayoutOptions{
Size: intPtr(0),
Orientation: stringPtr("portrait"),
Orientation: stringPtr(supportedPageOrientation[0]),
FirstPageNumber: uintPtr(1),
AdjustTo: uintPtr(100),
}
Expand Down
6 changes: 6 additions & 0 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ var supportedDrawingUnderlineTypes = []string{
// supportedPositioning defined supported positioning types.
var supportedPositioning = []string{"absolute", "oneCell", "twoCell"}

// supportedPageOrientation defined supported page setup page orientation.
var supportedPageOrientation = []string{"portrait", "landscape"}

// supportedPageOrder defined supported page setup page order.
var supportedPageOrder = []string{"overThenDown", "downThenOver"}

// builtInDefinedNames defined built-in defined names are built with a _xlnm prefix.
var builtInDefinedNames = []string{"_xlnm.Print_Area", "_xlnm.Print_Titles", "_xlnm.Criteria", "_xlnm._FilterDatabase", "_xlnm.Extract", "_xlnm.Consolidate_Area", "_xlnm.Database", "_xlnm.Sheet_Title"}

Expand Down

0 comments on commit f2e39c5

Please sign in to comment.