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(sheets-ui): validate pasted number formats (#7549)
wpxp1234565410a1a756c4
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.tsindex 95fa1e4c63..31152ca1df 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts@@ -243,6 +243,17 @@ describe('Test clipboard', () => {expect(cellValue?.v).toEqual(45607);});+ it('falls back to automatic parsing for unsupported named number formats', async () => {+ const html = `+ <style>.percent { mso-number-format: Percent; }</style>+ <table><tr><td class="percent">12%</td></tr></table>+ `;++ await expect(sheetClipboardService.legacyPaste(html)).resolves.toBe(true);+ expect(getValues(1, 1, 1, 1)?.[0]?.[0]?.v).toBe(0.12);+ expect(getStyles(1, 1, 1, 1)?.[0]?.[0]?.n?.pattern).toBe('0%');+ });+it('test formula with paste', async () => {const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.tsindex a37ead0853..c49a652b2e 100644--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts@@ -275,6 +275,11 @@ export class HtmlToUSMService {value = value.slice(1, -1);}const decoded = decodeMsoNumberFormat(value);+ // Excel can emit named formats such as `Percent` that are not valid Univer numfmt patterns.+ // Skip them so the external paste flow can infer a valid pattern from the displayed value.+ if (!numfmt.isValidFormat(decoded)) {+ continue;+ }// A rule can have multiple comma-separated selectorsselectors.split(',').forEach((sel) => {this._msoNumfmtMap.set(sel.trim(), decoded);