views:

32

answers:

1

In a WPF application, I need to generate data that can be put on the clipboard and pasted into excel. I need to paste something that can carry over data and formulas.

I was attempting OpenXML... but I'm not sure that works.

I am currently attempting to make raw "Spreadsheet ML" (This is different than OpenXML?)

Anyway, if anyone could provide me with some pointers... or better yet, C# that actually puts this kind of data on the clipboard, I would greatly appreciate it!

I posted another more specific question here: How do I get OpenXML onto the clipboard so that it will paste into Excel?

+1  A: 

I think the answer is NONE. That certainly used to be the case. Try this simple test, using the windows XP clipboard viewer (clipbrd.exe) which you can grab from any XP system to run on Vista/Windows7.

1) Copy from Excel.  Just a few cells, as you don't want to crash anything.
2) In clipbrd.exe, save as a file. Call it xl.clp  It may take awhile, as it will force 1) 3) Excel to render all clipboard formats.
4) Close Excel
5) Press PrintScreen to wipe the clipboard.
6) Open Excel again
7) In  clipbrd.exe, open xl.clp
8) Paste into Excel. 
Did you get your forumulas back?  I expect not

.

Ahhhh wait, there's more! I just tried this with Excel 2009. If I paste, I get the plain text version. But if I do a Paste Special, and pick "XML Spreadsheet", it works! And it even adjusts the forumlas if you paste into another row. Wow. this is new, and neat. So... YES you can, if you use this format. It looks like it's just plain text containing XML with near the top. You'd need to register "XML Spreadsheet" as a private data format.

Chris Thornton
I already know about the outbound (from Excel) works. That is how I discovered this in the first place. I just can't get it back into Excel. I will try this and let you know.
Phobis
Right, but Excel has about 24 outbound formats, and outside of this one, none are very useful inbound, except for CSV but that doesn't have formulas. My test proved that the XML Spreadsheet format IS useful inbound. you should be all set.
Chris Thornton
I tried what you said. I am running Windows 7 so I had to use some other programs to view/save the clipboard. I was able to put the identical data back on the clipboard, but I can not modify the data and have it work. There must be bits somewhere that are stating the size of the data or something. Anyway, I need a more definitive solution. This helps a bit, but I still can't get the clipboard to accept this format through C# and I can't even change the data using a clipboard application and have it accept the paste back in Excel.
Phobis
Make sure that other formats, such as OLE and Text, aren't present. Excel will prefer those.I'm pretty confident that if you present ONLY "XML Spreadsheet" to the clipboard, that's what'll be pasted.
Chris Thornton