如何使用剪贴板从.NET应用程序的数据转移到Excel?剪贴板、如何使用、应用程序、数据

2023-09-07 09:03:03 作者:风扬起思念

这是Excel的$ P从剪贴板中接收数据$ pferred格式?这些数据是在C#/。NET应用程序。

Which is Excel's preferred format for receiving data from the clipboard? The data is in a C# / .NET application.

我一直保存到CSV格式的剪贴板,但现在我要开始给的Excel格式的信息(例如,做一些大胆的细胞)。 CSV格式是远远不够的。

I had been saving to the clipboard in CSV format, but now I want to start giving Excel formatting information (eg. make some cells bold). CSV format is no longer enough.

当我从Excel中复制,剪贴板拥有24格式!

When I copy from Excel, the clipboard holds 24 formats!

System.Windows.Clipboard.GetDataObject().GetFormats().Dump();

EnhancedMetafile System.Drawing.Imaging.Metafile METAFILEPICT 位图 System.Drawing.Bitmap System.Windows.Media.Imaging.BitmapSource BIFF12 BIFF8 BIFF5 SymbolicLink DataInterchangeFormat XML US preadsheet HTML格式 文本 在统一codeTEXT System.String CSV 在富文本格式 嵌入源 在对象描述符 链接源 在链接源的描述符 链接 Format129 *

EnhancedMetafile System.Drawing.Imaging.Metafile MetaFilePict Bitmap System.Drawing.Bitmap System.Windows.Media.Imaging.BitmapSource Biff12 Biff8 Biff5 SymbolicLink DataInterchangeFormat XML Spreadsheet HTML Format Text UnicodeText System.String CSV Rich Text Format Embed Source Object Descriptor Link Source Link Source Descriptor Link Format129 *

推荐答案

我相信你所看到的是,Excel的prepares当你复制到许多不同的格式剪贴板取决于你在哪里结束粘贴数据它。你可能需要寻找到Office XML格式的Excel。

I believe what you're seeing is that Excel prepares the data when you copy to the clipboard in many different formats depending on where you end up pasting it. You probably need to look into the Office XML format for Excel.

有一个更好的主意的,请参阅此例如XML 在Wikipedia格式。虽然我以前从未使用过它,我是pretty的肯定Excel中只会让你直接在XML粘贴(如果这是正确的模式)。

See this example xml at Wikipedia for a better idea of the format. While I've never used it before, I'm pretty sure Excel would simply let you paste in the XML directly (if it's the right schema).