import { type CustomFormulaSetting, type FormulaSetting, type NoArgFormulaSetting, type SingleRefFormulaSetting, } from "../data-model/excel-table"; export function generateCellRowCol( string: string, formula: | FormulaSetting | SingleRefFormulaSetting | NoArgFormulaSetting | CustomFormulaSetting, sheetIndex: number, styleIndexMap: Record ) { string = string.toUpperCase(); let cell = ""; if ((formula).formula) { let form = formula; let formulaStr = form.formula.indexOf("=") == 0 ? form.formula.substring(1) : form.formula; let multiInsertCell = string.indexOf(":") > 0; let ref = form.referenceCells ? form.referenceCells : string; let startRef = multiInsertCell ? string.substring(0, string.indexOf(":")) : string; let column = startRef.replace(/[0-9]/g, ""); let row = parseInt(string.substr(column.length)); let returnType = form.returnType ? form.returnType : form.isArray || multiInsertCell ? ' t="str"' : ""; let style = "styleId" in form && typeof form.styleId === "string" && styleIndexMap[form.styleId] ? ' s="' + styleIndexMap[form.styleId] + '"' : ""; let arrayStr = form.isArray || multiInsertCell ? ' t="array" ref="' + ref + '"' : ""; cell = '" + formulaStr + ""; return { column, row, needCalcChain: false, isCustom: true, cell, }; } let column = string.replace(/[0-9]/g, ""); let row = parseInt(string.substr(column.length)); let needCalcChain = false; let chainCell = ""; if ((formula).noArgType) { const form = formula; if (form.noArgType == "NOW" || form.noArgType == "TODAY") { const styleString = "styleId" in form && typeof form.styleId === "string" && styleIndexMap[form.styleId] ? ' s="' + styleIndexMap[form.styleId] + '"' : ""; cell = '" + form.noArgType + "()"; } else { let value = "NOW()"; const styleString = "styleId" in form && typeof form.styleId === "string" && styleIndexMap[form.styleId] ? ' s="' + styleIndexMap[form.styleId!] + '"' : ""; cell = '" + form.noArgType.substring(4) + "(" + value + ")"; } chainCell = ''; needCalcChain = true; } else if ((formula).referenceCell) { const form = formula; let value = ""; if (typeof form.value != "undefined") { value = "," + form.value; } let className = ""; if (form.type == "COT") { className = "_xlfn."; } const styleString = "styleId" in form && typeof form.styleId === "string" && styleIndexMap[form.styleId] ? ' s="' + styleIndexMap[form.styleId!] + '"' : ""; cell = '" + className + form.type + "(" + form.referenceCell.toUpperCase() + value + ")"; chainCell = ''; needCalcChain = true; } else { const form = formula; cell = '" + "" + form.type + "(" + form.start.toUpperCase() + ":" + form.end.toUpperCase() + ")" + ""; } return { column, row, cell, needCalcChain, chainCell, }; }