1金币
本帖最后由 helloworldplus 于 2025-1-7 22:37 编辑
为方便打印,在A4纸情况下,我添加了两条参考线作为A4纸范围区域。
情况1. 导入新的表格,在工具栏上设置为A4纸,去掉所有边距以及页眉页脚,开启分页预览,第一页 分页预览的虚线和我的横向参考线长度能匹配上。参考线代码如下:
const createReference = (status: boolean) => {
const desigerDom = designerInstance?.designerDom // 封装的函数返回designer节点
const excelContainer: HTMLDivElement = desigerDom?.querySelector('.gc-ss-container') as HTMLDivElement
excelContainer.style.position = 'relative'
let topDomId = 'topDom'
let rightDomId = 'rightDOm'
if (status) {
let sheet = designerInstance?.getActiveSheet()
let offsetA1 = sheet.getCellRect(0, 0)
let offsetA1X = offsetA1.x
let offsetA1Y = offsetA1.y
// @ts-ignore 计算A4纸宽高
let paperSize = new GC.Spread.Sheets.Print.PaperSize()
// @ts-ignore 以A4纸测试
let { width, height } = paperSize.getPageSize(GC.Spread.Sheets.Print.PaperKind.a4)
width = width / 100
height = height / 100
// 顶部横向参考线
const topDom = document.createElement('div')
topDom.id = topDomId
topDom.style.cssText = `
position: absolute;
top: ${offsetA1Y - 1}px;
left: ${offsetA1X - 1}px;
width: ${width}in;
height: 1px;
background: red;
`
excelContainer.appendChild(topDom)
// 右侧纵向参考线
const rightDom = document.createElement('div')
rightDom.id = rightDomId
rightDom.style.cssText = `
position: absolute;
top: 0;
left: calc(${offsetA1X - 1}px + ${width}in);
width: 1px;
height: ${height}in;
background: red;
`
console.log(rightDom.style.cssText)
excelContainer.appendChild(rightDom)
} else {
const topDom = excelContainer.querySelector(`#${topDomId}`)
topDom?.parentNode?.removeChild(topDom)
const rightDom = excelContainer.querySelector(`#${rightDomId}`)
rightDom?.parentNode?.removeChild(rightDom)
}
情况2. 导入表格,通过代码清除所有边距以及页眉页脚,设置A4纸,参考线不变。然后开启分页预览,此时分页预览的第一页的虚线与参考线长度对不上,请问一下是什么原因导致的:(清除边距、页眉页脚,设置A4纸代码如下)
let activeSheet = spread?.getActiveSheet()
// @ts-ignore
let printInfo = new GC.Spread.Sheets.Print.PrintInfo()
// @ts-ignore
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(GC.Spread.Sheets.Print.PaperKind.a4))
printInfo.margin({ top: 0, bottom: 0, left: 0, right: 0, header: 0, footer: 0 })
activeSheet.printInfo(printInfo)
designer?.refresh()
请问一下,造成这个的可能原因是啥?
|
|