-1
我想用某個標題將DataTable導出爲excel。我正在使用XLWorkbook導出爲Excel。我的代碼導出DataTable excel完美,但我不知道如何添加一些標題。使用XL工作簿在c#中使用標題導出Excel
我根據數據表中的列大小,然後後添加的數據錶行希望Excel像下面
,這裏是我的C#代碼
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();
}
}
}
我不知道合併行和cells.could你幫我... – satyender