Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
How to set sheet names for Excel exported from webdatagrid
posted

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 dataTables
WebControl [] 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;
    }