Skip to content

Commit

Permalink
fix(formula): fix cell string type
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 authored and wpxp123456 committed Oct 29, 2024
1 parent 4f2595c commit c9b4dfc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,38 @@ describe('Test EndEditController', () => {
...target,
});
});
it('Text cell input formula', () => {
const cell: ICellData = {
s: {
n: {
pattern: '@@@',
},
},
t: null,
};

const inputCell = {
v: '=SUM(1)',
};

const cellData = getCellDataByInputCell(cell, inputCell);
const target = {
v: '=SUM(1)',
t: CellValueType.STRING,
s: {
n: {
pattern: '@@@',
},
},
f: null,
si: null,
p: null,
};

expect(cellData).toEqual({
...target,
});
});
it('Rich text cell', () => {
const cell = {
v: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,15 @@ export function getCellDataByInput(
const currentLocale = localeService.getCurrentLocale();
newDataStream = normalizeString(newDataStream, lexerTreeBuilder, currentLocale, functionService);

if (isFormulaString(newDataStream)) {
// Text format ('@@@') has the highest priority
if (cellData.s && styles?.get(cellData.s)?.n?.pattern === DEFAULT_TEXT_FORMAT) {
// If the style is text format ('@@@'), the data should be set as a string.
cellData.v = newDataStream;
cellData.f = null;
cellData.si = null;
cellData.p = null;
cellData.t = CellValueType.STRING;
} else if (isFormulaString(newDataStream)) {
if (cellData.f === newDataStream) {
return null;
}
Expand Down Expand Up @@ -791,13 +799,6 @@ export function getCellDataByInput(
cellData.f = null;
cellData.si = null;
}
} else if (cellData.s && styles?.get(cellData.s)?.n?.pattern === DEFAULT_TEXT_FORMAT) {
// If the style is text format ('@@@'), the data should be set as a string.
cellData.v = newDataStream;
cellData.f = null;
cellData.si = null;
cellData.p = null;
cellData.t = CellValueType.STRING;
} else if (numfmt.parseDate(newDataStream) || numfmt.parseNumber(newDataStream) || numfmt.parseTime(newDataStream)) {
// If it can be converted to a number and is not forced to be a string, then the style should keep prev style.
cellData.v = newDataStream;
Expand Down

0 comments on commit c9b4dfc

Please sign in to comment.