HI, I am having an Dataset which has multiple datatables and i want to display each datatable in separate workSheets( in the Same Excel file). I have done that without any issue by the below code. But the generated excel has sheets named as "WorkSheet1","WorkSheet2","WorkSheet3".. How can i set the sheet name in Server side code? Is there any other option to set the datatable names to the sheets?
Quick response will be much appreciated.
protected void btnGenerate_Click(object sender, EventArgs e)
{
//dsData - Dataset having multiple dataTablesWebControl [] prm = new WebControl[dsData.Tables.Count];
foreach (DataTable dt in dsData.Tables){prm[i] =this.GetWebDataGrid(dsData.Tables[i]);i++;}
WebExcelExporter objExcelExporter = new WebExcelExporter();objExcelExporter.DownloadName ="DownloadedSheet";objExcelExporter.Export(true, prm);
}
private WebDataGrid GetWebDataGrid(DataTable dt) { WebDataGrid wdg = new WebDataGrid(); wdg.AutoGenerateColumns = true; wdg.StyleSetName = "Caribbean"; wdg.DataSource = dt; wdg.DataBind(); this.Controls.Add(wdg); return wdg; }
Team.. Any update on this ??
Hello Elayaraja kannan,
The Export method of the WebExcelExporter has an overload which accepts as parametars a WebDataGrid and a Worksheet Object. It is possible to create the worksheet object with their own names and pass them into the Export method. The ExportMode will need to be set to Custom at first for this.
Please see the attached sample in the Button1_Click event which demonstrates how you can achieve this.
If you need any further assistance with this, please let me know and I will be glad to help.
Thanks a lot. I have modified the code slightly for my requirements and its working fine.