From a4132507f707bf3a20948cd92fadd2c21b0d2fa9 Mon Sep 17 00:00:00 2001 From: iyxan23 Date: Mon, 16 Sep 2024 13:53:00 +0700 Subject: [PATCH] fix,untested: different method of shifting colInfo --- src/xlsx.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/xlsx.ts b/src/xlsx.ts index f94093b..19f1b18 100644 --- a/src/xlsx.ts +++ b/src/xlsx.ts @@ -190,18 +190,14 @@ class XlsxTemplater { } else if (shift.direction === "col") { if (!colInfo) return; - for (const [key, val] of Object.entries(colInfo)) { - const keyNum = parseInt(key); - // shift infos that are over the current col, but duplicate the ones that - // is on the same col - if (keyNum === shift.col) { - for (let i = 0; i < shift.amount; i++) { - colInfo[keyNum + shift.amount] = val; - } - } else if (keyNum > shift.col) { - colInfo[keyNum + shift.amount] = val; - delete colInfo[keyNum]; - } + // colInfo is different, rather than using indexes, + // it stores min & max in "@_min" and "@_max" respectively. + for (const col of colInfo) { + const min = col["@_min"]; + const max = col["@_max"]; + + if (min >= shift.col) col["@_min"] += shift.amount; + if (max >= shift.col) col["@_max"] += shift.amount; } }