Cryptic exception copy/pasting from DataGridView into Excel 2002

8

Good Morning,

Running Visual Studio 2008 (C# 3.5). DataGridView is loaded manually (not data bound). Copy/pasting into Notepad/Wordpad works fine, but when I try to copy/paste into Excel I get this weird Exception:

Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))

This was working as of last Friday. I'm completely stumped. I am pretty sure this has worked in the past. I've tried rebooting, re-adding the DataGridView control. Any help much appreciated.

Regards, -Alan.

c#
.net
winforms
excel
asked on Stack Overflow Feb 23, 2011 by Alan

3 Answers

1

Perhaps some of your data is being interpreted by Excel as a formula (like 5/0).

You could try Pat's suggestion first (it's easier!).

Also, try pasting your text into Notepad first, copying everything from Notepad, and pasting that into Excel.

If you still get the errors, try pasting the first half of the text in Notepad. If that succeeds, paste the second half. They key is to try to narrow down which string of text is causing Excel to Barf on you.

answered on Stack Overflow Mar 17, 2011 by jp2code
0

My suggestion would be to instead of using ctrl+v to paste into excel, right click and select paste special and choose text formatting. It sounds like there is a different kind of encoding when you copy the contents to the clipboard(ctrl+c) There are some other options available for pasting if you right click the mouse button instead of using the paste hotkey(ctrl+p). Hopefully this helps ya out -Pat

answered on Stack Overflow Mar 17, 2011 by (unknown user)
0

Instead of calling Clipboard.SetDataObject(dataObject) , try this: Clipboard.SetDataObject(dataObject, true);. The 'true' parameter tells the Clipboard to take a copy of the data object. It worked for me.

answered on Stack Overflow Mar 4, 2014 by user1016736

User contributions licensed under CC BY-SA 3.0