Cryptic exception copy/pasting from DataGridView into Excel 2002
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.
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.
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
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.
精彩评论