代码拉取完成,页面将自动刷新
package excel
import (
"fmt"
"github.com/xuri/excelize/v2"
"gitee.com/ichub/go-factroy2024/framework/print-template/dto"
consts2 "gitee.com/ichub/go-factroy2024/framework/print-template/ruleconsts"
"strconv"
)
func SetPageLayout(t *TemplateExcel, layoutDto *dto.TLayoutDto) {
oristr := excelize.OrientationPortrait
if layoutDto.Direction == "横向" {
oristr = excelize.OrientationLandscape
}
size := 9
if layoutDto.Size == "A3" {
size = 8
} else if layoutDto.Size == "A4" {
size = 9
} else if layoutDto.Size == "A5" {
size = 11
}
// 9 | A4 paper (210 mm by 297 mm)
// 10 | A4 small paper (210 mm by 297 mm)
// 11 | A5 paper (148 mm by 210 mm)
if err := t.File.SetPageLayout(consts2.SHEET_NAME_BODY,
excelize.BlackAndWhite(false),
//excelize.FirstPageNumber(2),
excelize.PageLayoutOrientation(oristr),
excelize.PageLayoutPaperSize(size),
//excelize.FitToHeight(2),excelize.FitToWidth(2),
//excelize.PageLayoutScale(50),
); err != nil {
fmt.Println(err)
}
left, _ := strconv.ParseFloat(layoutDto.MarginLeft, 64) // excelize.PageMarginLeft(0.7),
top, _ := strconv.ParseFloat(layoutDto.MarginTop, 64) // excelize.PageMarginTop(0.8),
right, _ := strconv.ParseFloat(layoutDto.MarginRight, 64) // excelize.PageMarginRight(0.5),
bottom, _ := strconv.ParseFloat(layoutDto.MarginBottom, 64) // excelize.PageMarginBottom(0.8),
t.File.SetPageMargins(consts2.SHEET_NAME_BODY,
excelize.PageMarginLeft(left/10),
excelize.PageMarginTop(top/10),
excelize.PageMarginRight(right/10),
excelize.PageMarginBottom(bottom/10),
)
fmt.Println(layoutDto.ToString())
}
func SetPageLayoutDefault(t *TemplateExcel) {
if err := t.File.SetPageLayout(consts2.SHEET_NAME_BODY,
excelize.BlackAndWhite(false),
//excelize.FirstPageNumber(2),
excelize.PageLayoutOrientation(excelize.OrientationLandscape),
excelize.PageLayoutPaperSize(9),
//excelize.FitToHeight(2),excelize.FitToWidth(2),
//excelize.PageLayoutScale(50),
); err != nil {
fmt.Println(err)
}
t.File.SetPageMargins(consts2.SHEET_NAME_BODY,
excelize.PageMarginLeft(0.7),
excelize.PageMarginTop(0.8),
excelize.PageMarginRight(0.5),
excelize.PageMarginBottom(0.8),
)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。