本帖最后由 Wilson.Zhang 于 2025-7-7 08:50 编辑
产品:SpreadJS
版本:18.1.3
调研编号:SJS-30440
Last Review:2025-07-07
当前进展:paint方法定义了仅在单元格有value时绘制,而copyTo调用时未复制值,逻辑冲突,改写paint方法支持无value时的绘制逻辑。
1、自定义单元格类型:FileUploadCellType
2、将单元格放入table中
3、通过自定义命令插入新的table行,并复制单元格类型到新插入行,当被复制单元格值不为空时,复制单元格类型失败,自定义命令如下:
// 向上插入
const customTableInsertRowsAboveCopyStyleCommand = {
canUndo: true,
name: 'customTableInsertRowsAboveCopyStyleCommand',
execute: function (context: any, options: any, isUndo: any) {
const Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
const sheet = context.getSheetFromName(options.sheetName);
sheet.suspendPaint();
const selections = options.selections;
let table: any = null;
if (selections) {
const selection = selections[0];
// 获取表格区域
table = sheet.tables.find(selection.row, selection.col);
sheet.autoMerge(table.range(), GC.Spread.Sheets.AutoMerge.AutoMergeDirection.none);
sheet.addRows(selection.row, selection.rowCount);
sheet.getRange(selection.row, 0, selection.rowCount, sheet.getColumnCount()).locked(false);
const startColumn = table.startColumn();
const endColumn = table.endColumn();
const colCount = endColumn - startColumn + 1;
const rowCount = selection.rowCount;
// 遍历所选行数rowCount,并从selection.row + rowCount开始(旧selection第一行)
// 按照顺序(selection.row + rowCount对应selection.row)依次对应将样式、高度复制给新插入的行
for (let i = 0; i < rowCount; i++) {
const sourceRow = selection.row + rowCount + i;
const targetRow = selection.row + i;
// 复制样式和高度
sheet.copyTo(
sourceRow,
startColumn,
targetRow,
startColumn,
1,
colCount,
GC.Spread.Sheets.CopyToOptions.style |
GC.Spread.Sheets.CopyToOptions.span |
GC.Spread.Sheets.CopyToOptions.formula |
GC.Spread.Sheets.CopyToOptions.defaultValue |
GC.Spread.Sheets.CopyToOptions.tag,
// GC.Spread.Sheets.CopyToOptions.all 使用all可以成功复制
);
}
// 重新计算table行高(向上插入必须重新计算)
const range = table.range();
const tableTag = sheet?.getTag(range.row, range.col) || {};
const rowHeight = tableTag['rowHeight'] || 35;
for (let i = 1; i < range.rowCount; i++) {
sheet.setRowHeight(range.row + i, rowHeight);
}
}
sheet.resumePaint();
Commands.endTransaction(context, options);
if (table) {
// 检查表格是否自动合并,若是则刷新
// checkTableAutoMerge(sheet, table);
}
return true;
}
},
};
4、初始dataSource如下:
const dataSource = {
Sheet1: {
file_table: [
{
file1: [
{name: '文件', path: 'https://img2.baidu.com/it/u=4057383394,3546683081&fm=253&fmt=auto&app=138&f=JPEG?w=402&h=500'}
]
}
]
}
};
5、如下图(详情见附件):
|