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 a开发者_StackOverflowm 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?
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.
It can't be done. I've recently been through this with Microsoft (support & the Office dev team) and Office will not accept any OpenXML format from 3rd party apps. For Word you need to use rtf and for Excel/PPT you need to use html.
But we tried duplicating what Word does copy/pasting to itself and it will not take that from a 3rd party app, even if it's the only format offered. And MS confirmed this behavior for us.
Phobis, try the next article: Link
Then you can use this code, look the tag ss:Formula.
<Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="3" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
<Row ss:Index="2">
<Cell ss:Index="2"><Data ss:Type="String">A</Data></Cell>
<Cell><Data ss:Type="String">B</Data></Cell>
<Cell ss:Formula="=CONCATENATE(RC[-2],RC[-1])"><Data ss:Type="String">AB</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
<Cell ss:Formula="=SUM(RC[-2]:RC[-1])"><Data ss:Type="Number">3</Data></Cell>
</Row>
</Table>
That works for me.
精彩评论