Click here to Skip to main content
14,734,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a datagrid with DataGridTemplateColumns. I want to export the datagrid to excel file.

I got a method works great for the exporting except it doesn't work for the TemplateColumns.

I attached my method here.


private void ExportToExcel()
{
    gridTestScript.SelectAllCells();
    gridTestScript.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
    ApplicationCommands.Copy.Execute(null, gridTestScript);
    String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
    String result = (string)Clipboard.GetData(DataFormats.Text);
    gridTestScript.UnselectAllCells();
    System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Intel\test.xls");
    file.WriteLine(result.Replace(',', ' '));
    file.Close();

    MessageBox.Show(" Exporting DataGrid data to Excel file created");
}



Any help would be really appreciated

Thanks
Posted

1 solution

   
Comments
codingStar 24-Mar-14 2:48am
   
Hi jacobjohn196,

thanks for the quick reply. The thing is what I am doing is using WPF datagrid. And the link provided is about asp.net. I'm still not sure how I can get this solved.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900