How use clipboard to move data from .NET applicati

2019-07-27 00:10发布

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

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.


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

System.Windows.Clipboard.GetDataObject().GetFormats().Dump();
  • 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
  • *

标签: c# .net excel
1条回答
欢心
2楼-- · 2019-07-27 00:29

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.

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).

查看更多
登录 后发表回答