Chepene
Chepene

Reputation: 1128

Paste data from clipboard to excel in right format

In performance analyzer I copy data from table in clipboard.

enter image description here

And then paste it in excel file. The result is:

enter image description here

But when I paste it in text editor, I simple looks like:

Function Name Inclusive Samples Exclusive Samples Inclusive Samples % Exclusive Samples %
[clr.dll] 26 26 39.39 39.39
Bee.Client.Common.BeeRight.CheckRightsForBeeUser() 10 0 15.15 0.00
Bee.Client.Common.BeeRight.get_Invoke() 6 0 9.09 0.00
Bee.Client.Common.BeeRight.Method(string,string) 13 0 19.70 0.00
Bee.Client.Common.Custom.FmCustom..ctor() 9 0 13.64 0.00

So can you tell me, how can I archive this effect?

Thanks!

Update

I'll try to explain. I have DataGridView in my winform application. I wrote some function, which copy data from table into clipboard (the result looks like the text in my example). If I paste this text from clipboard to excel, the result will be excel file with data from clipboard, but there will be no formatting at all and this excel will be hard to read.

I wonder, how they prepare data from table (pic 1) such a way, that when I paste it to excel, it has formatting (pic 2), and when I paste it in text editor, we saw raw text..

Upvotes: 0

Views: 4015

Answers (1)

Anton
Anton

Reputation: 4684

The cause, why the direct work between your datagrid and Excel is good, is the implementation of the DataGridView component and its reaction to Copy operation, and the behavior of the application, you want to paste the content into. It can use some special codes, which are ignored by Notepad.

EDIT

So, now I understand your interest pretty well. I don't know how it works in C#, but in Java it looks so.

Every time you have any information in the clipboard there are a lot of variants, how other applications can use this content.

Suppose I want to get the content from the clipboard. I do it so:

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);

but now I should determine how the information should look for my application, and here your question begins.

If I have a picture in the clipboard, I have only 1 possible representation of it:

[mimetype=image/x-java-image;representationclass=java.awt.Image]

If I have some text from Notepad, there are already 27 variants:

[mimetype=application/x-java-text-encoding;representationclass=[B]
[mimetype=application/x-java-serialized-object;representationclass=java.lang.String]
[mimetype=text/plain;representationclass=java.io.Reader]
[mimetype=text/plain;representationclass=java.lang.String]
[mimetype=text/plain;representationclass=java.nio.CharBuffer]
and so on...

If I have some cells from an Excel sheet, there are 56 variants:

[mimetype=application/x-java-text-encoding;representationclass=[B]
[mimetype=text/html;representationclass=java.io.Reader]
[mimetype=text/html;representationclass=java.lang.String]
[mimetype=text/html;representationclass=java.nio.CharBuffer]
[mimetype=text/html;representationclass=[C]
and so on...

there is even an Image-variant for Excel-cells!

[mimetype=image/x-java-image;representationclass=java.awt.Image]

That is why it is possible to copy some cells from Excel and paste them into Paint as bitmap! It is not possible for Notepad of course, because its developers did not want to work with this presentation.

Now we can see, the clipboard is not so primitive how it can seem to be. Each time an application can analyze the content and take the best variant of it.

Now you can try to find some infos for C# development. I'm sure, you'll get it!

Upvotes: 6

Related Questions