Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The .NET Framework places <code>DataFormats.CommaSeparatedValue</code> on the clipboard as Unicode text. But as mentioned at <a href="http://www.syncfusion.com/faq/windowsforms/faq_c98c.aspx#q899q" rel="noreferrer">http://www.syncfusion.com/faq/windowsforms/faq_c98c.aspx#q899q</a>, Excel expects CSV data to be a UTF-8 memory stream (it is difficult to say whether .NET or Excel is at fault for the incompatibility).</p> <p>The solution I've come up with in my own application is to place two versions of the tabular data on the clipboard simultaneously as tab-delimited text and as a CSV memory stream. This allows the destination application to acquire the data in its preferred format. Notepad and Excel prefer the tab-delimited text, but you can force Excel to grab the CSV data via the Paste Special... command for testing purposes.</p> <p>Here is some example code (note that WinForms-equivalents from the WPF namespaces are used here):</p> <pre><code>// Generate both tab-delimited and CSV strings. string tabbedText = //... string csvText = //... // Create the container object that will hold both versions of the data. var dataObject = new System.Windows.DataObject(); // Add tab-delimited text to the container object as is. dataObject.SetText(tabbedText); // Convert the CSV text to a UTF-8 byte stream before adding it to the container object. var bytes = System.Text.Encoding.UTF8.GetBytes(csvText); var stream = new System.IO.MemoryStream(bytes); dataObject.SetData(System.Windows.DataFormats.CommaSeparatedValue, stream); // Copy the container object to the clipboard. System.Windows.Clipboard.SetDataObject(dataObject, true); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload