mirror of
https://github.com/dream-num/univer.git
synced 2026-08-29 07:13:59 +08:00
fix(sheet): ensure numfmt crash not effect all (#6201)
This commit is contained in:
@@ -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),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user