Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update formula after deleting rows or columns #393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion packages/core/src/modules/rowcol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Context } from "../context";
import { Sheet } from "../types";
import { getSheetIndex } from "../utils";
import { getcellFormula } from "./cell";
import { functionStrChange } from "./formula";
import { execfunction, functionStrChange } from "./formula";
import { update } from "./format";

const refreshLocalMergeData = (merge_new: Record<string, any>, file: Sheet) => {
Object.entries(merge_new).forEach(([, v]) => {
Expand Down Expand Up @@ -1175,6 +1176,30 @@ export function insertRowCol(
// }
}

export function updateFormulaDeletingRowCol(ctx: Context, newCalcChain: any[]) {
for (
let SheetIndex = 0;
SheetIndex < ctx.luckysheetfile.length;
SheetIndex += 1
) {
const calcChain = newCalcChain;
const { data } = ctx.luckysheetfile[SheetIndex];

for (let i = 0; i < calcChain!.length; i += 1) {
const calc: any = _.cloneDeep(calcChain![i]);
const calc_r = calc.r;
const calc_c = calc.c;
const func = data![calc_r]![calc_c]!.f as string;
const funcV = execfunction(ctx, func, calc_r, calc_c, undefined, true);
[, data![calc_r]![calc_c]!.v] = funcV;
data![calc_r]![calc_c]!.m = update(
data![calc_r]![calc_c]!.ct?.fa || "General",
data![calc_r]![calc_c]!.v
);
}
}
}

export function deleteRowCol(
ctx: Context,
op: {
Expand Down Expand Up @@ -2052,6 +2077,9 @@ export function deleteRowCol(
file.data = d;
file.config = cfg;
file.calcChain = newCalcChain;
// 删除行列后,更新公式所在单元格的值
updateFormulaDeletingRowCol(ctx, newCalcChain);
Copy link
Contributor

@zyc9012 zyc9012 Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use jfrefreshgrid?


if (newFilterObj != null) {
file.filter = newFilterObj.filter;
file.filter_select = newFilterObj.filter_select;
Expand Down