Skip to content

Commit

Permalink
fix(cf): numerical calculations add type checking (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound committed Mar 23, 2024
1 parent fec1888 commit c392497
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ColorKit, ObjectMatrix, Range } from '@univerjs/core';
import { CellValueType, ColorKit, ObjectMatrix, Range } from '@univerjs/core';
import { isObject } from '@univerjs/engine-render';
import { RuleType } from '../../base/const';
import type { IColorScale, IConditionFormatRule } from '../../models/type';
Expand All @@ -34,7 +34,7 @@ export const colorScaleCellCalculateUnit: ICalculateUnit = {
Range.foreach(range, (row, col) => {
const cell = worksheet?.getCellRaw(row, col);
const v = cell && cell.v;
if (!isNullable(v)) {
if (!isNullable(v) && cell?.t === CellValueType.NUMBER) {
const _value = Number(v);
!Number.isNaN(_value) && matrix.setValue(row, col, _value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ObjectMatrix, Range } from '@univerjs/core';
import { CellValueType, ObjectMatrix, Range } from '@univerjs/core';
import { RuleType } from '../../base/const';
import type { IDataBarRenderParams } from '../../render/type';
import type { IConditionFormatRule, IDataBar } from '../../models/type';
Expand All @@ -36,7 +36,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {
Range.foreach(range, (row, col) => {
const cell = worksheet?.getCellRaw(row, col);
const v = cell && cell.v;
if (!isNullable(v)) {
if (!isNullable(v) && cell?.t === CellValueType.NUMBER) {
const _value = Number(v);
!Number.isNaN(_value) && matrix.setValue(row, col, _value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const highlightCellCalculateUnit: ICalculateUnit = {
switch (ruleConfig.subType) {
case SubRuleType.number:{
const v = cellValue && Number(cellValue.v);
if (isNullable(v) || Number.isNaN(v)) {
if (isNullable(v) || Number.isNaN(v) || cellValue?.t !== CellValueType.NUMBER) {
return false;
}
const subRuleConfig = ruleConfig as INumberHighlightCell;
Expand Down Expand Up @@ -160,7 +160,7 @@ export const highlightCellCalculateUnit: ICalculateUnit = {
}
case SubRuleType.timePeriod:{
const value = getCellValue(cellValue!);
if (isNullable(value) || Number.isNaN(Number(value))) {
if (isNullable(value) || Number.isNaN(Number(value)) || cellValue?.t !== CellValueType.NUMBER) {
return false;
}
const subRuleConfig = ruleConfig as ITimePeriodHighlightCell;
Expand Down Expand Up @@ -228,7 +228,7 @@ export const highlightCellCalculateUnit: ICalculateUnit = {
case SubRuleType.average:{
const value = cellValue && cellValue.v;
const v = Number(value);
if (isNullable(value) || Number.isNaN(v)) {
if (isNullable(value) || Number.isNaN(v) || cellValue?.t !== CellValueType.NUMBER) {
return false;
}
const subRuleConfig = ruleConfig as IAverageHighlightCell;
Expand Down Expand Up @@ -263,7 +263,7 @@ export const highlightCellCalculateUnit: ICalculateUnit = {

const v = Number(value);

if (isNullable(value) || Number.isNaN(v)) {
if (isNullable(value) || Number.isNaN(v) || cellValue?.t !== CellValueType.NUMBER) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ObjectMatrix, Range } from '@univerjs/core';
import { CellValueType, ObjectMatrix, Range } from '@univerjs/core';
import type { NumberOperator } from '../../base/const';
import { RuleType } from '../../base/const';

Expand All @@ -38,7 +38,7 @@ export const iconSetCalculateUnit: ICalculateUnit = {
Range.foreach(range, (row, col) => {
const cell = worksheet?.getCellRaw(row, col);
const v = cell && cell.v;
if (!isNullable(v)) {
if (!isNullable(v) && cell?.t === CellValueType.NUMBER) {
const _value = Number(v);
!Number.isNaN(_value) && matrix.setValue(row, col, _value);
}
Expand Down

0 comments on commit c392497

Please sign in to comment.