1 Star 0 Fork 0

ichub/go-factroy2024

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SetPageLayout.go 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
leijmdas 提交于 2024-02-01 12:27 . add
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),
)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ichub/go-factroy2024.git
git@gitee.com:ichub/go-factroy2024.git
ichub
go-factroy2024
go-factroy2024
v1.0.0

搜索帮助