diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue index 0e874b5..8af9e30 100644 --- a/src/views/business/lab/excelEdit/excelEditDialog.vue +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -25,6 +25,7 @@ import bindForm from './methods/bind/bindForm' import bindTable from './methods/bind/bindTable' import bindPicture from './methods/bind/bindPicture' +import bindPagingSeal from './methods/pagingSeal' import { importSjsFile } from './index' const emits = defineEmits(['initComplete']) GC.Spread.Common.CultureManager.culture('zh-cn') @@ -49,6 +50,12 @@ // bindTable(spread, data) // 绑定图片 handleBindPicture() + // 骑缝章 + bindPagingSeal( + spread, + 'http://111.198.10.15:21408/test/校准专用章新_1711095570061.png', + 180, 120 + ) }) } // 执行导出文件 @@ -90,7 +97,7 @@ nextTick(() => { designer = new GC.Spread.Sheets.Designer.Designer(designerContainerRef.value) // 表格设计器实例 spread = designer.getWorkbook() // 创建工作簿实例 - // sheet = spread.getActiveSheet() // 获取当前活动工作表 + sheet = spread.getActiveSheet() // 获取当前活动工作表 console.log('当前工作表sheet', sheet) initComplete() diff --git a/src/views/business/lab/excelEdit/excelEditDialog.vue b/src/views/business/lab/excelEdit/excelEditDialog.vue index 0e874b5..8af9e30 100644 --- a/src/views/business/lab/excelEdit/excelEditDialog.vue +++ b/src/views/business/lab/excelEdit/excelEditDialog.vue @@ -25,6 +25,7 @@ import bindForm from './methods/bind/bindForm' import bindTable from './methods/bind/bindTable' import bindPicture from './methods/bind/bindPicture' +import bindPagingSeal from './methods/pagingSeal' import { importSjsFile } from './index' const emits = defineEmits(['initComplete']) GC.Spread.Common.CultureManager.culture('zh-cn') @@ -49,6 +50,12 @@ // bindTable(spread, data) // 绑定图片 handleBindPicture() + // 骑缝章 + bindPagingSeal( + spread, + 'http://111.198.10.15:21408/test/校准专用章新_1711095570061.png', + 180, 120 + ) }) } // 执行导出文件 @@ -90,7 +97,7 @@ nextTick(() => { designer = new GC.Spread.Sheets.Designer.Designer(designerContainerRef.value) // 表格设计器实例 spread = designer.getWorkbook() // 创建工作簿实例 - // sheet = spread.getActiveSheet() // 获取当前活动工作表 + sheet = spread.getActiveSheet() // 获取当前活动工作表 console.log('当前工作表sheet', sheet) initComplete() diff --git a/src/views/business/lab/excelEdit/methods/pagingSeal.ts b/src/views/business/lab/excelEdit/methods/pagingSeal.ts new file mode 100644 index 0000000..3aee1b4 --- /dev/null +++ b/src/views/business/lab/excelEdit/methods/pagingSeal.ts @@ -0,0 +1,51 @@ +/** + * 骑缝章 + * 思路:根据sheet页数去裁剪图片 + * */ +export default function bindPagingSeal( + spread: any, + url: string, // 图片的源路径或 Base64 编码字符串。 + width: number, // 图片的宽度。 + height: number, // 图片的高度。 + startRow = 0, // 起始行 + x = 0, // 图片左上角的 x 坐标。 + y = 0, // 图片左上角的 y 坐标。 + name?: string, // 图片的名称。 +) { + const sheetCount = spread.getSheetCount() + const itemPictureWidth = width / sheetCount // 每份章的宽度 + const itemPictureWidthProportion = itemPictureWidth / width // 每个占章总宽度的比例 + console.log('几个sheet页', sheetCount) + console.log('每份章的宽度', itemPictureWidth) + console.log('每个占章总宽度的比例', itemPictureWidthProportion) + + for (let i = 0; i < sheetCount; i++) { + const sheet = spread.getSheet(i) + // 获取工作表的最后一列索引 + const lastColumnIndex = sheet.getColumnCount() - 1 + const picture = sheet.shapes.addPictureShape( + name || 'picture', + url, + x, + y, + itemPictureWidth, + height, + ) + // 设置图片位置到最右边 + picture.startRow(startRow) // 设置起始行 + picture.startColumn(lastColumnIndex) // 设置起始列 + picture.startColumnOffset(0 - itemPictureWidth) // 调整偏移量以适应图片宽度 + // 可选:设置结束行列以更好地控制图片范围 + // picture.endRow(0) + picture.endColumn(lastColumnIndex) + // 裁剪 + picture.pictureFormat({ + crop: { + left: i * itemPictureWidthProportion, // The left value% of the image will be cropped + right: 1 - (i + 1) * itemPictureWidthProportion, // The right value% of the image will be cropped + top: 0, // The top value% of the image will be cropped + bottom: 0, // The bottom value% of the image will be cropped + }, + }) + } +}