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: check cell data and remove linebreak in v filed (#2382)
Ran Luocfc2e0a760c1
diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.tsindex 7a5ce040ed..7f3b5af8a6 100644--- a/packages/core/src/sheets/worksheet.ts+++ b/packages/core/src/sheets/worksheet.ts@@ -702,16 +702,22 @@ export interface ICell {* @returns pure text in this cell*/export function extractPureTextFromCell(cell: Nullable<ICellData>): string {- if (!cell) return '';+ if (!cell) {+ return '';+ }const richTextValue = cell.p?.body?.dataStream;- if (richTextValue) return richTextValue;+ if (richTextValue) {+ return richTextValue;+ }const rawValue = cell.v;if (typeof rawValue === 'string') {- if (cell.t === CellValueType.BOOLEAN) return rawValue.toUpperCase();- return rawValue;+ if (cell.t === CellValueType.BOOLEAN) {+ return rawValue.toUpperCase();+ }+ return rawValue.replace(/[\r\n]/g, '');};if (typeof rawValue === 'number') {diff --git a/packages/engine-render/src/components/docs/view-model/document-view-model.ts b/packages/engine-render/src/components/docs/view-model/document-view-model.tsindex 96717a9a18..86900ae920 100644--- a/packages/engine-render/src/components/docs/view-model/document-view-model.ts+++ b/packages/engine-render/src/components/docs/view-model/document-view-model.ts@@ -493,6 +493,10 @@ export class DocumentViewModel implements IDisposable {children: DataStreamTreeNode[],nodeType = DataStreamTreeNodeType.SECTION_BREAK) {+ if (children.length === 0) {+ throw new Error('Missing `paragraphs` or `sectionBreaks` fields, or doesn\'t correspond to the location in `dataStream`.');+ }+for (const child of children) {child.parent = parent;parent.children.push(child);