How to export columns from a datatable to a specific cell in Excel (c# )

Viewed 19

I have a datatable that returns a large amount of Data. I want to export specific columns to specifc cells in excel using c#.

So far I am able to export whole datatable to excel using below code:

 protected void btnExcel_Click(object sender, EventArgs e)
    {

        HSSFWorkbook workbook = new HSSFWorkbook();
        MemoryStream ms = new MemoryStream();
        ExportUtility EU = new ExportUtility();
        string qry = printPr.Value;
        DataTable dtnew =getDataTableFromQuery(qry);


        EU.ExportDataTableToWorkbook(dtnew, "DownloadSheet", workbook);

        //Response 

       
        string saveAsFileName = string.Format("abc" + ".xls");
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", 
        saveAsFileName));
        Response.Clear();
        Response.BinaryWrite(EU.GetBytes(workbook));
        Response.End();
        Response.Clear();
    }

How can I export columns to specific columns in Excel ?

0 Answers
Related