mirror of
https://github.com/dream-num/univer.git
synced 2026-08-29 07:13:59 +08:00
fix(clipboard): fix pasted data with number format error case (#6257)
This commit is contained in:
@@ -160,10 +160,6 @@ export function parseFormattedDate(value: string) {
|
||||
return numfmt.parseDate(value);
|
||||
}
|
||||
|
||||
export function parseFormattedValue(value: string) {
|
||||
return numfmt.parseValue(value);
|
||||
}
|
||||
|
||||
export function parseFormattedTime(value: string) {
|
||||
return numfmt.parseTime(value);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
|
||||
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
|
||||
import { excelDateTimeSerial, isDate, parseFormattedValue } from '../../../basics/date';
|
||||
import { getNumfmtParseValueFilter } from '@univerjs/core';
|
||||
import { excelDateTimeSerial, isDate } from '../../../basics/date';
|
||||
import { ErrorType } from '../../../basics/error-type';
|
||||
import { getFractionalPart } from '../../../engine/utils/math-kit';
|
||||
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
|
||||
@@ -46,7 +47,7 @@ export class Timevalue extends BaseFunction {
|
||||
|
||||
if (timeTextObject.isString()) {
|
||||
const value = `${timeTextObject.getValue()}`;
|
||||
const parsedTime = parseFormattedValue(value);
|
||||
const parsedTime = getNumfmtParseValueFilter(value);
|
||||
if (parsedTime) {
|
||||
let { v, z } = parsedTime;
|
||||
|
||||
|
||||
@@ -130,7 +130,6 @@ function getNumberCellValue(sheet: Worksheet, row: number, col: number) {
|
||||
return null;
|
||||
}
|
||||
if (typeof v === 'string' && t === CellValueType.NUMBER) {
|
||||
// use this way to instead of numfmt.parseNumber(v as string).v as number;
|
||||
return Number(sheet.getCellRaw(row, col)!.v);
|
||||
}
|
||||
return Number(v);
|
||||
|
||||
@@ -42,9 +42,7 @@ import type {
|
||||
ISheetDiscreteRangeLocation,
|
||||
} from '../../services/clipboard/type';
|
||||
import type { IScrollStateWithSearchParam } from '../../services/scroll-manager.service';
|
||||
|
||||
import type { IUniverSheetsUIConfig } from '../config.schema';
|
||||
|
||||
import {
|
||||
BooleanNumber,
|
||||
DEFAULT_WORKSHEET_COLUMN_WIDTH,
|
||||
@@ -52,6 +50,7 @@ import {
|
||||
DEFAULT_WORKSHEET_ROW_HEIGHT,
|
||||
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
|
||||
extractPureTextFromCell,
|
||||
getNumfmtParseValueFilter,
|
||||
handleStyleToString,
|
||||
ICommandService,
|
||||
IConfigService,
|
||||
@@ -61,16 +60,13 @@ import {
|
||||
isFormulaString,
|
||||
IUniverInstanceService,
|
||||
LocaleService,
|
||||
numfmt,
|
||||
ObjectMatrix,
|
||||
RxDisposable,
|
||||
Tools,
|
||||
UniverInstanceType,
|
||||
} from '@univerjs/core';
|
||||
|
||||
import { MessageType } from '@univerjs/design';
|
||||
import { convertBodyToHtml, DocSelectionRenderService } from '@univerjs/docs-ui';
|
||||
|
||||
import { IRenderManagerService, withCurrentTypeOfRenderer } from '@univerjs/engine-render';
|
||||
import {
|
||||
InsertColMutation,
|
||||
@@ -635,7 +631,7 @@ export class SheetClipboardController extends RxDisposable {
|
||||
},
|
||||
};
|
||||
} else {
|
||||
const pattern = numfmt.parseNumber(text);
|
||||
const pattern = getNumfmtParseValueFilter(text);
|
||||
if (pattern?.z) {
|
||||
cellValue = {
|
||||
[range.rows[0]]: {
|
||||
|
||||
@@ -35,9 +35,9 @@ import {
|
||||
CustomRangeType,
|
||||
DEFAULT_STYLES,
|
||||
generateRandomId,
|
||||
getNumfmtParseValueFilter,
|
||||
isTextFormat,
|
||||
IUniverInstanceService,
|
||||
numfmt,
|
||||
ObjectMatrix,
|
||||
Range,
|
||||
Rectangle,
|
||||
@@ -364,7 +364,7 @@ export function getSetCellValueMutations(
|
||||
cellValue.t = CellValueType.STRING;
|
||||
} else {
|
||||
const content = String(value.v);
|
||||
const numfmtValue = numfmt.parseValue(content);
|
||||
const numfmtValue = getNumfmtParseValueFilter(content);
|
||||
if (numfmtValue?.v !== undefined && typeof numfmtValue.v === 'number') {
|
||||
// If the numeric string will lose precision when converted to a number, set the cell type to force string
|
||||
// e.g. 123456789123456789
|
||||
@@ -474,7 +474,7 @@ export function getSetCellStyleMutations(
|
||||
(newValue.s as IStyleData).n = style?.n;
|
||||
} else {
|
||||
const content = String(value.v);
|
||||
const numfmtValue = numfmt.parseValue(content);
|
||||
const numfmtValue = getNumfmtParseValueFilter(content);
|
||||
if (numfmtValue?.z) {
|
||||
if (!newValue.s) {
|
||||
newValue.s = {};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
/* eslint-disable antfu/consistent-list-newline */
|
||||
import type { IFunctionService, ISequenceNode, LexerTreeBuilder } from '@univerjs/engine-formula';
|
||||
import { LocaleType, numfmt } from '@univerjs/core';
|
||||
import { getNumfmtParseValueFilter, LocaleType, numfmt } from '@univerjs/core';
|
||||
import { matchToken, sequenceNodeType } from '@univerjs/engine-formula';
|
||||
|
||||
const fullWidthToHalfWidthMap: { [key: string]: string } = {
|
||||
@@ -94,7 +94,7 @@ export function normalizeString(str: string, lexerTreeBuilder: LexerTreeBuilder,
|
||||
}
|
||||
|
||||
// Formatting Numbers
|
||||
const parsedValue = numfmt.parseValue(normalStr);
|
||||
const parsedValue = getNumfmtParseValueFilter(normalStr);
|
||||
|
||||
return parsedValue == null ? str : normalStr;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ function normalizeFormulaString(str: string, normalStr: string, lexerTreeBuilder
|
||||
const endIndex = node.endIndex + totalOffset + 1;
|
||||
_normalStr = replaceString(str.slice(startIndex, endIndex), _normalStr, startIndex, endIndex);
|
||||
} else if (node.nodeType !== sequenceNodeType.ARRAY) {
|
||||
const parsedValue = numfmt.parseValue(token);
|
||||
const parsedValue = getNumfmtParseValueFilter(token);
|
||||
|
||||
if (parsedValue == null) {
|
||||
const startIndex = node.startIndex + totalOffset + 1;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
import type { ICustomRange, IDocumentBody, IDocumentData, ITextRun, ITextStyle, Nullable } from '@univerjs/core';
|
||||
import type { SpreadsheetSkeleton } from '@univerjs/engine-render';
|
||||
import type { ISheetSkeletonManagerParam } from '../../sheet-skeleton-manager.service';
|
||||
|
||||
import type {
|
||||
ICellDataWithSpanInfo,
|
||||
IClipboardPropertyItem,
|
||||
@@ -27,7 +26,7 @@ import type {
|
||||
IUniverSheetCopyDataModel,
|
||||
} from '../type';
|
||||
import type { IAfterProcessRule, IPastePlugin } from './paste-plugins/type';
|
||||
import { CustomRangeType, DEFAULT_WORKSHEET_ROW_HEIGHT, generateRandomId, numfmt, ObjectMatrix, skipParseTagNames } from '@univerjs/core';
|
||||
import { CustomRangeType, DEFAULT_WORKSHEET_ROW_HEIGHT, generateRandomId, getNumfmtParseValueFilter, ObjectMatrix, skipParseTagNames } from '@univerjs/core';
|
||||
import { handleStringToStyle, textTrim } from '@univerjs/ui';
|
||||
import { extractNodeStyle } from './parse-node-style';
|
||||
import parseToDom, { convertToCellStyle, generateParagraphs } from './utils';
|
||||
@@ -474,8 +473,8 @@ export class HtmlToUSMService {
|
||||
* "<span style="mso-spacerun:yes"> </span>1,234.57 "
|
||||
*/
|
||||
if (cell.innerHTML.includes('mso-spacerun:yes')) {
|
||||
const cellText = cell.innerHTML.replace(/<span[^>]*mso-spacerun:yes[^>]*>[\s\S]*?<\/span>/gi, '');
|
||||
const parseInfo = numfmt.parseNumber(cellText);
|
||||
const cellText = cell.innerHTML.replace(/<span[^>]*mso-spacerun:yes[^>]*>[\s\S]*?<\/span>/gi, '').replace(/\s/g, '');
|
||||
const parseInfo = getNumfmtParseValueFilter(cellText);
|
||||
|
||||
if (parseInfo && parseInfo.v !== undefined && parseInfo.v !== null) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user