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();
}
}
}
In the List properties, under General > Column Titles, change the setting to 'Hide". Then go to under General > Column Titles, change the setting to 'Hide". or simply select the header (by going to ancestor select list column title style ) and box type none or cut it.
It is possible to generate Excel exports with some static images or text in the Excel's headers. The steps are: Start with a new or existing Excel template and click on Insert menu and there click on Header & Footer submenu. This adds Header & Footer to your Excel document.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With