Adding Ttile to worksheet using XLWorkbook class in C# .Net

Last Reply on Jan 20, 2016 04:07 AM By Shashikant

Posted on Jan 20, 2016 04:06 AM

HI ,

I want to add the title rows to excel sheet ( Top of the rows as header) using Closedxml class here is the code i have copied from this site.

it is working correctlry without adding title to sheet.

 

public void ExportDataToExcel(DataTable dt, string fileName)
    {                                          
            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt);                    
                wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                wb.Style.Font.Bold = true;

                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");

                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    wb.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                    Response.End();
                }
            }                      
    }

 

You are viewing reply posted by: Shashikant on Jan 20, 2016 04:07 AM.
Posted on Jan 20, 2016 04:07 AM