简体   繁体   English

以正确的格式将数据从剪贴板粘贴到Excel

[英]Paste data from clipboard to excel in right format

In performance analyzer I copy data from table in clipboard. 在性能分析器中,我从剪贴板中的中复制数据。

在此处输入图片说明

And then paste it in excel file . 然后将其粘贴到excel文件中 The result is: 结果是:

在此处输入图片说明

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 [clr.dll] 26 26 39.39 39.39
Bee.Client.Common.BeeRight.CheckRightsForBeeUser() 10 0 15.15 0.00 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.get_Invoke()6 0 9.09 0.00
Bee.Client.Common.BeeRight.Method(string,string) 13 0 19.70 0.00 Bee.Client.Common.BeeRight.Method(字符串,字符串)13 0 19.70 0.00
Bee.Client.Common.Custom.FmCustom..ctor() 9 0 13.64 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. 我的Winform应用程序中有DataGridView。 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. 如果我将文本从剪贴板粘贴到excel,结果将是带有剪贴板数据的excel文件,但根本不会格式化,并且该excel将很难阅读。

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.. 我想知道他们是如何从表(图1)准备数据的,当我将其粘贴到excel时,它具有格式(图2),并且当我将其粘贴到文本编辑器中时,我们看到了原始文本。

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. 原因是您的数据网格和Excel之间的直接工作良好,原因是要实现DataGridView组件的实现及其对Copy操作的反应,以及您想要将内容粘贴到其中的应用程序的行为。 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. 我不知道它如何在C#中工作,但在Java中看起来却是如此。

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: 如果我在剪贴板中的图片,我有只1可能的表示:

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

If I have some text from Notepad, there are already 27 variants: 如果我从记事本中得到一些文字,则已经有27种变体:

[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: 如果我在Excel工作表中有一些单元格,则有56种变体:

[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! 甚至还有Excel单元格的图像变体!

[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! 这就是为什么可以从Excel复制某些单元格并将其作为位图粘贴到Paint中的原因! 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. 现在,您可以尝试查找一些有关C#开发的信息。 I'm sure, you'll get it! 我敢肯定,你会明白的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM