From a datatable I want to remove headers. How can I remove headers or first row which includes the headers.
if (dt.Rows.Count > 0)
{
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt, "Customers");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + fname + ".xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
If you don't want to see the headers in the worksheet, don't add the whole table, but only the data. For example, the task is to add all rows of the dt
table starting from the first cell of the first row in the worksheet:
var ws = wb.Worksheets.Add("Customers");
ws.FirstRow().FirstCell().InsertData(dt.Rows);