本帖最后由 Matthew.Xue 于 2025-3-13 10:57 编辑
以下是我的代码:现在实现了拖动复制的时候,不复制绑定的path,但是有个问题,复制完后,过了几秒钟,数值丢失了:
以下是我的代码:
- DragFill: function (spread) {
- spread.bind(GC.Spread.Sheets.Events.DragFillBlock, function (e, info) {
- let fillRange = info.fillRange;
- let bindingPathRec = new Map();
- // 边界检查
- if (
- !info.sheet ||
- !fillRange ||
- fillRange.rowCount <= 0 ||
- fillRange.colCount <= 0
- ) {
- console.error("Invalid fill range or sheet reference.");
- return;
- }
- try {
- for (
- let row = fillRange.row;
- row < fillRange.row + fillRange.rowCount;
- row++
- ) {
- for (
- let col = fillRange.col;
- col < fillRange.col + fillRange.colCount;
- col++
- ) {
- // 获取当前单元格的bindingPath
- let path = info.sheet.getBindingPath(row, col);
- // 如果path存在,则记录;否则,跳过该单元格
- if (path) {
- // 使用复合键存储信息
- let compositeKey = `${row},${col}`;
- bindingPathRec.set(compositeKey, {
- row: row,
- col: col,
- path: path,
- });
- }
- // 如果path不存在,则不做任何操作
- }
- }
- setTimeout(() => {
- try {
- // 执行完之后,将之前保存的bindingPath设置回去
- for (let [key, value] of bindingPathRec.entries()) {
- info.sheet.setBindingPath(value.row, value.col, value.path);
- console.log(key, ":", value, "setTimeout");
- }
- } catch (setErr) {
- console.error("Error setting binding path:", setErr);
- }
- }, 0);
- } catch (getErr) {
- console.error("Error getting binding path:", getErr);
- }
- });
- }
复制代码
|
|