How to keep colors when copy-pasting from datagridview to excel?

前端 未结 2 921
我寻月下人不归
我寻月下人不归 2021-01-07 10:47

I use the following CellFormatting code to conditionally color rows in my datagridview.

private void SGridView_CellFormatting(object sender, DataGridViewCel         


        
2条回答
  •  暖寄归人
    2021-01-07 11:40

    I believe that DataGridView by default stores in the clipboard only tab delimited data without formatting

    But you can write your custom Copy with Formatting function using the method, described in

    http://www.tcx.be/blog/2005/copy-html-to-clipboard/

    Just in case if you will want to ask a question how to handle copy event to write some custom code and put formatted HTML to clipboard, I would suggest using PreviewKeyDown event and write something like

    if (e.KeyData.ToString() == "C, Control") {  your formatting code goes here  
    } 
    

提交回复
热议问题