27

I am trying to ask a question on SE, have some mock data in Excel I've copied, and am simply trying to paste in to my question. I've done this before dozens of times, but suddenly am having this issue.

However, when I do so, I get prompted to upload an image. (This happens with Ctrl + V and also right click --> Paste):

Enter image description here

Am I overlooking something?

Edit: Playing around, I can copy from Firefox/browsers and Word, and paste in to the box as usual. Excel seems to be the only one giving the issue so far.

Edit2: Other users are still having this issue.

15
  • 2
    It looks like the thing inside your clipboard is an image, and it's triggering the mechanism that allows you to copy and paste image data. Try re-copying it. Dec 14, 2018 at 17:01
  • @SonictheInclusiveHedgehog - I've tried again and again. I think it's the way Excel maybe puts the data in the clipboard?
    – BruceWayne
    Dec 14, 2018 at 17:02
  • 6
    I can replicate. Copy a range from excel, paste here into stackexchange, prompt to paste image box pops up. Pasting into Notepad pastes the same clipboard as text, tab delimited, as expected. @BruceWayne FWIW, you could copy and paste into notepad and recopy/paste into stackexchange. I also, generally, paste into ozh.github.io/ascii-tables and choose the "Header Location:" of "Spreadsheet" for pasting into Stackoverflow in a nice formatted way that includes the excel A...Z, 1...N column and row headers.
    – JNevill
    Dec 14, 2018 at 17:08
  • @JNevill - Yeah, I can put the Excel info in Word (or whatever), then paste to SO. Coming straight from Excel seems to throw it off. Thanks for the link to that page, looks quite helpful!
    – BruceWayne
    Dec 14, 2018 at 17:10
  • 3
    @BruceWayne: Office programs typically put data on the clipboard in multiple formats, often including images, just in case. Dec 14, 2018 at 17:10
  • 1
    @NathanTuggy - Then perhaps SE (or SO generally) made a change to the way data is pasted? I was able to paste from Excel without issue until recently. I can't remember if it coincides with the re-formatting of the "Upload" box SO did, or not.
    – BruceWayne
    Dec 14, 2018 at 17:12
  • @BruceWayne: Yeah, they added image pasting about that time, so I'm pretty sure that's the problem. Dec 14, 2018 at 17:12
  • @NathanTuggy but what's odd, if my data is copied as an image, why won't SO simply accept the image? Or as you said, does my copy exist as two types (data & image) at the same time?
    – BruceWayne
    Dec 14, 2018 at 17:16
  • 1
    @BruceWayne: From the screenshot, it looks like you could hit Add Picture after the initial dialog pops up to upload it immediately. The flow is still a little wonky, though, as it led you down another path that then disables that. Dec 14, 2018 at 17:19
  • 8
    Hitting "Add Picture" does work: i.stack.imgur.com/wYrRI.png It's a little worrying though as we are always pestering SO posters to paste their data as text so we can replicate. This new "Feature" is going to give them an easier workflow to bad behavior.
    – JNevill
    Dec 14, 2018 at 17:21
  • @NathanTuggy - Good call. But, as JNevill mentions, I can hit "Add Picture" and the data will paste ...as an image. But we want to paste as Text.
    – BruceWayne
    Dec 14, 2018 at 17:36
  • 3
    You can also use Ctrl+Shift+V to paste as plain text, which works correctly.
    – animuson StaffMod
    Dec 14, 2018 at 17:36
  • 9
    Picture should be the last option, not the first, when choosing among available clipboard data types
    – user1228
    Dec 14, 2018 at 19:30
  • 1
    Cross-site post on Meta.SO: Copy/paste from MS Word triggers image upload. Mar 29, 2019 at 0:07
  • 1
    They should just remove the image copy/paste until they can fix copy pasting from excel/word/libreoffice. Could also add an option to let the user select pasting as data or upload to imugr....
    – pyCthon
    May 27, 2019 at 16:16

2 Answers 2

5

Same bug report on Meta Stack Overflow has been declined back in September 2019 with the following reasoning:

We are not going to be working on a fix for this at the time being. Seems that it is only happening with Word for Mac. And there is a good workaround in place as well (see the accepted answer below). So given that, and the other things in our pipeline, this is going to be a . Sorry.

2
  • 3
    Interesting, as this is happening to me in Windows, not Mac. Perhaps it's an Office-wide issue...?
    – BruceWayne
    Apr 21, 2020 at 20:47
  • @Bruce might be, worth pinging Yaakov on the MSO report and ask to reconsider the rejection. Apr 21, 2020 at 23:27
3

It's possible to detect if a Microsoft Office application is the clipboard source

Taken from Pasting from Microsoft Excel defaults to pasting an image via the Uploader™ I looked into how you might fix this:

Converting tables to images is the opposite of what I normally want to do in an edit (image to markdown table!). There's a related bug where isn't not clear what you want paste: Copying text from OneNote and pasting creates an image instead of text but as you should never be pasting an image of a table in, we should actually fix this one!

If the devs can see a `text/HTML' data type on the clipboard event, and then interrogate the html returned you can detect where it's come from:

arguments[0].clipboardData.getData('text/HTML')  
`<html xmlns:v="urn:schemas-microsoft-com:vml"\r\nxmlns:o="urn:schemas-microsoft-com:office:office"\r\nxmlns:x="urn:schemas-microsoft-com:office:excel"\r\nxmlns="http://www.w3.org/TR/REC-html40">\r\n\r\n<head>\r\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\r\n<meta name=ProgId content=Excel.Sheet>\r\n<meta name=Generator content="Microsoft Excel 15">

Which reveals xmlns:x="urn:schemas-microsoft-com:office:excel" i.e. it's from Excel!

Which presumably means you could change behaviour based on where the content is pasted from, and paste plain text?

This possibly explains why it's only on Windows.

Below is a small snippet that shows it's possible to detect and work around this bug:

function handlePaste(e) {
  let clipboardData;
  let htmlData;
  let textData;

  // Get pasted data via clipboard API
  clipboardData = e.clipboardData || window.clipboardData;
  htmlData = clipboardData.getData('text/HTML');
  if (htmlData) {
    parser = new DOMParser();
    domData = parser.parseFromString(htmlData, 'text/html');
    // 'urn:schemas-microsoft-com:office:excel'
    let {
      length,
      [length - 1]: officeApp
    } = domData?.querySelector('html')?.getAttribute('xmlns:x')?.split(':') ?? [];
    if (officeApp === 'excel') {
      console.log('found Excel Data')
      textData = clipboardData.getData('Text');
      const selection = window.getSelection();
      if (!selection.rangeCount) return false;
      selection.deleteFromDocument();
      selection.getRangeAt(0).insertNode(document.createTextNode(textData));
      event.preventDefault();
    }
  }

}

document.getElementById('editableDiv').addEventListener('paste', handlePaste);
<div id='editableDiv' contenteditable='true' style="border: 1px solid lightgrey;">Paste Excel data here</div>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .