简体   繁体   中英

How use clipboard to move data from .NET application to Excel?

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
  • *

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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