fix(sheet): ensure numfmt crash not effect all (#6201)

This commit is contained in:
VicKun
2025-11-24 19:48:35 +08:00
committed by GitHub
parent 16fa81a7da
commit 57c1d68143
+16 -8
View File
@@ -27,19 +27,27 @@ interface IPatternPreview {
export const getPatternPreview = (pattern: string, value: number, locale: INumfmtLocaleTag = 'en'): IPatternPreview => {
// in the source code of numfmt, the formatColor function will read the the partitions[3]
const formatColor = numfmt.formatColor(pattern, value);
const color = formatColor ? String(formatColor) : undefined;
const result = numfmt.format(pattern, value, { locale, throws: false });
if (value < 0) {
// pay attention, controllers/numfmt.controller.ts
// in the pattern, the negative value color may be upper case one , so if we read a color with UpperCase, we should return the color with lower case for our theme system
try {
const formatColor = numfmt.formatColor(pattern, value);
const color = formatColor ? String(formatColor) : undefined;
const result = numfmt.format(pattern, value, { locale, throws: false });
if (value < 0) {
// pay attention, controllers/numfmt.controller.ts
// in the pattern, the negative value color may be upper case one , so if we read a color with UpperCase, we should return the color with lower case for our theme system
return {
result,
color,
};
}
return {
result,
color,
};
} catch (e) {
console.warn('getPatternPreview error:', pattern, e);
}
return {
result,
result: String(value),
};
};