Skip to content

Raw Handling: Paste from MS Excel no longer creates a table block #42570

Open

Description

@admturner

Description

Pasting content from Microsoft Excel as a table is not working as expected. I expect to content copied from an Excel spreadsheet to create a table block when pasted in the editor. Instead, it pastes as a paragraph block.

Copying and pasting from Google Sheets works as expected -- it creates a table block in the editor. But copying and pasting from Excel appears to strip the HTML during an intermediary step between pasting and block creation (see screen recording).

This issue appears to have originated in v5.9, but I'm not sure. I used the "WP Downgrade | Specific Core Version" plugin to downgrade from 6.0.1 to 5.8.4 (my end users noticed the issue begin around March or April) and copy-paste from Excel works as expected in 5.8.4.

Step-by-step reproduction instructions

  1. Create an Excel spreadsheet with some content.
  2. Go to Pages > Add New.
  3. Copy the content of the Excel spreadsheet into the WP editor.
  4. See error.

Repeat steps from Google Sheets to see expected behavior.

Screenshots, screen recording, code snippet

On a fresh local WordPress 6.0.1 installation:

wp6-0-1-excel-table-format

Environment info

  • WordPress 6.0.1, not using Gutenberg plugin, default Twenty Twenty-One theme, and no plugins active. Issue appears in Twenty-Twenty Two theme as well, and when downgraded as far as WordPress 5.9.
  • Firefox 102.0.1 (64-bit). Issue also appears in Chrome (103.0.5060.134) and Edge (103.0.1264.62).
  • Desktop with Windows 10.
  • WordPress running in local Docker environment. Issue also appears in WP 6.0.1 running in hosted environment.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Activity

  1. t-hamano commented on Nov 12, 2022

    @t-hamano
    Contributor

    @admturner
    Thank you for your contribution.

    I have confirmed that this process for Windows, added by #33607, caused the regression.

    // Remove Windows-specific metadata appended within copied HTML text.
    html = removeWindowsFragments( html );

    Received HTML data differs depending on the presence or absence of this process:

    With removeWindowsFragments
     <col width=70 span=2 style='width:53pt'>
     <tr height=24 style='height:18.0pt'>
      <td height=24 class=xl65 width=70 style='height:18.0pt;width:53pt'>Cell 1</td>
      <td class=xl65 width=70 style='width:53pt'>Cell 2</td>
     </tr>
     <tr height=24 style='height:18.0pt'>
      <td height=24 class=xl65 style='height:18.0pt'>Cell 3</td>
      <td class=xl65>Cell 4</td>
     </tr>
    
    Without removeWindowsFragments
     <html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
    
    <head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 15">
    <link id=Main-File rel=Main-File
    href="file:///C:/Users/TETSUA~1.HAM/AppData/Local/Temp/msohtmlclip1/01/clip.htm">
    <link rel=File-List
    href="file:///C:/Users/TETSUA~1.HAM/AppData/Local/Temp/msohtmlclip1/01/clip_filelist.xml">
    <style>
    <!--table
    	{mso-displayed-decimal-separator:"\.";
    	mso-displayed-thousand-separator:"\,";}
    @page
    	{margin:.75in .7in .75in .7in;
    	mso-header-margin:.3in;
    	mso-footer-margin:.3in;}
    .font5
    	{color:windowtext;
    	font-size:6.0pt;
    	font-weight:400;
    	font-style:normal;
    	text-decoration:none;
    	font-family:游ゴシック, monospace;
    	mso-font-charset:128;}
    tr
    	{mso-height-source:auto;
    	mso-ruby-visibility:none;}
    col
    	{mso-width-source:auto;
    	mso-ruby-visibility:none;}
    br
    	{mso-data-placement:same-cell;}
    td
    	{padding-top:1px;
    	padding-right:1px;
    	padding-left:1px;
    	mso-ignore:padding;
    	color:black;
    	font-size:11.0pt;
    	font-weight:400;
    	font-style:normal;
    	text-decoration:none;
    	font-family:游ゴシック, monospace;
    	mso-font-charset:128;
    	mso-number-format:General;
    	text-align:general;
    	vertical-align:bottom;
    	border:none;
    	mso-background-source:auto;
    	mso-pattern:auto;
    	mso-protection:locked visible;
    	white-space:nowrap;
    	mso-rotate:0;}
    .xl65
    	{font-family:"Noto Sans JP", sans-serif;
    	mso-font-charset:128;}
    ruby
    	{ruby-align:left;}
    rt
    	{color:windowtext;
    	font-size:6.0pt;
    	font-weight:400;
    	font-style:normal;
    	text-decoration:none;
    	font-family:游ゴシック, monospace;
    	mso-font-charset:128;
    	mso-char-type:katakana;
    	display:none;}
    -->
    </style>
    </head>
    
    <body link="#0563C1" vlink="#954F72">
    
    <table border=0 cellpadding=0 cellspacing=0 width=140 style='border-collapse:
     collapse;width:106pt'>
    <!--StartFragment-->
     <col width=70 span=2 style='width:53pt'>
     <tr height=24 style='height:18.0pt'>
      <td height=24 class=xl65 width=70 style='height:18.0pt;width:53pt'>Cell 1</td>
      <td class=xl65 width=70 style='width:53pt'>Cell 2</td>
     </tr>
     <tr height=24 style='height:18.0pt'>
      <td height=24 class=xl65 style='height:18.0pt'>Cell 3</td>
      <td class=xl65>Cell 4</td>
     </tr>
    <!--EndFragment-->
    </table>
    
    </body>
    
    </html>
    

    As the above data shows, data pasted from MS Excel has Startfragment and EndFragment in the Table tag.

    Since #33607 removes the outside of the fragments, the removal of the table tag would have caused it to no longer match the table schema.

  2. t-hamano commented on Nov 12, 2022

    @t-hamano
    Contributor

    I think it would be better to add the test proposed in #34235 first, so that the resolution of this issue does not cause regression #33607 to the contrary.

  3. changed the title [-]Paste from MS Excel no longer creates a table block[/-] [+]Raw Handling: Paste from MS Excel no longer creates a table block[/+] on Aug 3, 2023
  4. moved this to Needs Dev / Todo in WordPress 6.4 Editor Taskson Aug 30, 2023
  5. ellatrix commented on Oct 9, 2023

    @ellatrix
    Member

    @admturner, or anyone else, could you please share the HTML that is logged in the console so we can fix and add a test? Example: #46832. No need to provide an example file. Thanks!

  6. t-hamano commented on Oct 9, 2023

    @t-hamano
    Contributor

    Below are the screencast and recorded logs. I also investigated the cause of this issue in this comment.

    bcf47031253d3eb4ab3d51c3c112a657.mp4
    Received HTML:
    
     
     <col width=70 span=3 style='width:53pt'>
     <tr height=24 style='height:18.0pt'>
      <td height=24 width=70 style='height:18.0pt;width:53pt'>One</td>
      <td width=70 style='width:53pt'>Two</td>
      <td width=70 style='width:53pt'>Three</td>
     </tr>
     <tr height=24 style='height:18.0pt'>
      <td height=24 style='height:18.0pt'>Four</td>
      <td>Five</td>
      <td>Six</td>
     </tr>Received HTML:
    
     
     <col width=70 span=3 style='width:53pt'>
     <tr height=24 style='height:18.0pt'>
      <td height=24 width=70 style='height:18.0pt;width:53pt'>One</td>
      <td width=70 style='width:53pt'>Two</td>
      <td width=70 style='width:53pt'>Three</td>
     </tr>
     <tr height=24 style='height:18.0pt'>
      <td height=24 style='height:18.0pt'>Four</td>
      <td>Five</td>
      <td>Six</td>
     </tr>
    
    Received plain text:
    
     One	Two	Three
    Four	Five	Six
    
    Processed HTML piece:
    
     <p>One Two Three<br>Four Five Six</p>
    

    Testing Environment

    • OS: Windows 11
    • Browser: Version 117.0.5938.150
    • Excel: Microsoft® Excel® 2016 MSO (verion 2309 build 16.0.16827.20130) 64bit
  7. t-hamano commented on Oct 10, 2023

    @t-hamano
    Contributor

    Are you positive that this is the markup you're receiving?

    Yes. Why such HTML is received is discussed in this comment.

    Even in the gif image seen at the beginning of this issue, you can see that such HTML is recorded in the browser console, so it shouldn't be a problem in my environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions