C# Add excel text-formatted data to clipboard

前端 未结 3 1146
逝去的感伤
逝去的感伤 2021-01-19 10:15

In C# I need to copy data-grid rows to excel. Because some values in a row are doubles, \"-Infinity\" values are possible.

I\'ve tried to copy the rows

3条回答
  •  独厮守ぢ
    2021-01-19 10:53

    The win32 api solution did not work for me. I had had random crashes. Following code works fine, also with unicode chars.

    var xml = File.ReadAllText(@"..\..\SampleData\Clipboard-Example3.xml");
    
    var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
    var dataObject = new DataObject();
    dataObject.SetData("XML SpreadSheet", stream);
    
    Clipboard.Clear();
    Clipboard.SetDataObject(dataObject);
    

提交回复
热议问题