diff --git a/packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts b/packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts index a4ff2e111e7..43e842fe8a0 100644 --- a/packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts +++ b/packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts @@ -49,8 +49,12 @@ export class ContentModelPastePlugin implements EditorPlugin { /** * Construct a new instance of Paste class * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN + * @param allowExcelNoBorderTable Allow table copied from Excel without border */ - constructor(private unknownTagReplacement: string = 'SPAN') {} + constructor( + private unknownTagReplacement: string = 'SPAN', + private allowExcelNoBorderTable?: boolean + ) {} /** * Get name of this plugin @@ -110,7 +114,11 @@ export class ContentModelPastePlugin implements EditorPlugin { case 'excelDesktop': if (pasteType === 'normal' || pasteType === 'mergeFormat') { // Handle HTML copied from Excel - processPastedContentFromExcel(ev, this.editor.getTrustedHTMLHandler()); + processPastedContentFromExcel( + ev, + this.editor.getTrustedHTMLHandler(), + this.allowExcelNoBorderTable + ); } break; case 'googleSheets': diff --git a/packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts b/packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts index 08fd346901c..dcd39ef1e22 100644 --- a/packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts +++ b/packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts @@ -18,7 +18,8 @@ const DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4'; export function processPastedContentFromExcel( event: ContentModelBeforePasteEvent, - trustedHTMLHandler: TrustedHTMLHandler + trustedHTMLHandler: TrustedHTMLHandler, + allowExcelNoBorderTable?: boolean ) { const { fragment, htmlBefore, clipboardData } = event; const html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined; @@ -53,7 +54,7 @@ export function processPastedContentFromExcel( } addParser(event.domToModelOption, 'tableCell', (format, element) => { - if (element.style.borderStyle === 'none') { + if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') { format.borderBottom = DEFAULT_BORDER_STYLE; format.borderLeft = DEFAULT_BORDER_STYLE; format.borderRight = DEFAULT_BORDER_STYLE; diff --git a/packages-content-model/roosterjs-content-model-plugins/test/paste/ContentModelPastePluginTest.ts b/packages-content-model/roosterjs-content-model-plugins/test/paste/ContentModelPastePluginTest.ts index b9d35c35a6d..faf5cf00b0d 100644 --- a/packages-content-model/roosterjs-content-model-plugins/test/paste/ContentModelPastePluginTest.ts +++ b/packages-content-model/roosterjs-content-model-plugins/test/paste/ContentModelPastePluginTest.ts @@ -105,7 +105,8 @@ describe('Content Model Paste Plugin Test', () => { expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith( event, - trustedHTMLHandler + trustedHTMLHandler, + undefined /*allowExcelNoBorderTable*/ ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 3); expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1); @@ -122,7 +123,8 @@ describe('Content Model Paste Plugin Test', () => { expect(ExcelFile.processPastedContentFromExcel).not.toHaveBeenCalledWith( event, - trustedHTMLHandler + trustedHTMLHandler, + undefined /*allowExcelNoBorderTable*/ ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED); expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1); @@ -138,7 +140,8 @@ describe('Content Model Paste Plugin Test', () => { expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith( event, - trustedHTMLHandler + trustedHTMLHandler, + undefined /*allowExcelNoBorderTable*/ ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1); @@ -154,7 +157,8 @@ describe('Content Model Paste Plugin Test', () => { expect(ExcelFile.processPastedContentFromExcel).toHaveBeenCalledWith( event, - trustedHTMLHandler + trustedHTMLHandler, + undefined /*allowExcelNoBorderTable*/ ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);