Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: fix copy html error (#6861)
wpxp123456eca1af9ee6a9
diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 0aec76b94f..bd82b2ca2d 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -181,7 +181,7 @@ export { addLinkToDocumentModel, getEmptyCell, isNotNullOrUndefined, isRangesEquexport { createDocumentModelWithStyle } from './sheets/util';export { SheetViewModel } from './sheets/view-model';export { getWorksheetUID, Workbook } from './sheets/workbook';-export { extractPureTextFromCell, getOriginCellValue, Worksheet } from './sheets/worksheet';+export { extractPureTextFromCell, getDisplayValueFromCell, getOriginCellValue, Worksheet } from './sheets/worksheet';export { Skeleton } from './skeleton';export * from './types/const';export { skipParseTagNames } from './types/const/clipboard';diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.tsindex d793ad248b..56ee72a23f 100644--- a/packages/core/src/sheets/worksheet.ts+++ b/packages/core/src/sheets/worksheet.ts@@ -1387,7 +1387,7 @@ export function extractPureTextFromCell(cell: Nullable<ICellData>): string {if (cell.t === CellValueType.BOOLEAN) {return rawValue.toUpperCase();}- return rawValue.replace(/\r/g, '');+ return rawValue.replace(/[\r\n]/g, '');};if (typeof rawValue === 'number') {@@ -1400,6 +1400,39 @@ export function extractPureTextFromCell(cell: Nullable<ICellData>): string {return '';}+export function getDisplayValueFromCell(cell: Nullable<ICellDataForSheetInterceptor>): string {+ if (!cell) {+ return '';+ }++ const richTextValue = cell.p?.body?.dataStream;+ if (richTextValue) {+ return BuildTextUtils.transform.getPlainText(richTextValue);+ }++ const displayValue = cell.v;++ if (displayValue === null || displayValue === undefined) {+ return '';+ }++ if (cell.t === CellValueType.BOOLEAN) {+ if (typeof displayValue === 'string') {+ return displayValue.toUpperCase();+ }++ if (typeof displayValue === 'number') {+ return displayValue ? 'TRUE' : 'FALSE';+ }+ }++ if (typeof displayValue === 'boolean') {+ return displayValue ? 'TRUE' : 'FALSE';+ }++ return String(displayValue);+}+export function getOriginCellValue(cell: Nullable<ICellData>) {if (cell === null) {return '';diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.tsindex 2f5353b402..e367e2f82d 100644--- a/packages/engine-render/src/components/sheets/extensions/font.ts+++ b/packages/engine-render/src/components/sheets/extensions/font.ts@@ -25,7 +25,7 @@ import type { IDrawInfo } from '../../extension';import type { IFontCacheItem } from '../interfaces';import type { SheetComponent } from '../sheet-component';import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';-import { CellValueType, extractPureTextFromCell, HorizontalAlign, Range, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';+import { CellValueType, getDisplayValueFromCell, HorizontalAlign, Range, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';import { FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics';import { VERTICAL_ROTATE_ANGLE } from '../../../basics/text-rotation';import { clampRange, inViewRanges } from '../../../basics/tools';@@ -516,7 +516,7 @@ export class Font extends SheetExtension {const paddingBottom = padding.b ?? DEFAULT_PADDING_DATA.b;const { vertexAngle = 0, wrapStrategy, cellData } = fontCache;if (cellData?.v === undefined || cellData?.v === null) return;- const text = extractPureTextFromCell(cellData);+ const text = getDisplayValueFromCell(cellData);const { startX, startY, endX, endY } = renderFontCtx;const cellWidth = endX - startX - paddingLeft - paddingRight;const cellHeight = endY - startY - paddingTop - paddingBottom;diff --git a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts b/packages/engine-render/src/components/sheets/sheet.render-skeleton.tsindex bf458ad8cd..9ab49517b0 100644--- a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts@@ -48,6 +48,7 @@ import {DEFAULT_STYLES,extractPureTextFromCell,getColorStyle,+ getDisplayValueFromCell,HorizontalAlign,IConfigService,IContextService,@@ -600,7 +601,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {if (style?.tb === WrapStrategy.WRAP) {const skeleton = new DocSimpleSkeleton(- extractPureTextFromCell(cell),+ getDisplayValueFromCell(cell),getFontStyleString(style).fontCache,style?.tb === WrapStrategy.WRAP,colWidth - paddingLeft - paddingRight,diff --git a/packages/sheets-table/src/model/filter-util/manual.ts b/packages/sheets-table/src/model/filter-util/manual.tsdeleted file mode 100644index 35be907815..0000000000--- a/packages/sheets-table/src/model/filter-util/manual.ts+++ /dev/null@@ -1,54 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { ICellData, Nullable } from '@univerjs/core';-import { BuildTextUtils, CellValueType } from '@univerjs/core';--/**- * Get pure text in a cell.- * @param cell- * @returns pure text in this cell- */-export function extractPureTextFromCell(cell: Nullable<ICellData>): string {- if (!cell) {- return '';- }-- const richTextValue = cell.p?.body?.dataStream;- if (richTextValue) {- return BuildTextUtils.transform.getPlainText(richTextValue);- }-- const rawValue = cell.v;-- if (typeof rawValue === 'string') {- if (cell.t === CellValueType.BOOLEAN) {- return rawValue.toUpperCase();- }-- // the browser will automatically cache the regular expression, so we don't need to cache it manually- return rawValue.replace(/[\r\n]/g, '');- };-- if (typeof rawValue === 'number') {- if (cell.t === CellValueType.BOOLEAN) return rawValue ? 'TRUE' : 'FALSE';- return rawValue.toString();- };-- if (typeof rawValue === 'boolean') return rawValue ? 'TRUE' : 'FALSE';-- return '';-}diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.tsindex 4645defc39..aa2515dfbd 100644--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts@@ -244,11 +244,14 @@ export class SheetClipboardController extends RxDisposable {onCopyCellContent(row: number, col: number): string {const cell = currentSheet!.getCell(row, col);- let content = '';if (cell?.p?.body?.paragraphs || cell?.p?.body?.textRuns) {- content = convertBodyToHtml(cell.p);- } else if (cell) {- content = extractPureTextFromCell(cell);+ return convertBodyToHtml(cell.p);+ }++ const content = extractPureTextFromCell(cell);++ if (content.trim() === '') {+ return content;}/**