How to Convert Table into a Normal Range of cells while exporting excel in c#. By default it is in Table format, not able to sort due to tabel format. I need this to normal range of cells.
After excel exported, you able to do in manually by selecting Table tools (design) and have option to select "convert to range". I need to done via code by using closedXML.
System.Data.DataTable dataTable = magicButtonApi.ExportData(magicButtonCheckedNodesBE); var fileName = "Excel_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx"; //save the file to server temp folder string fullPath = Path.Combine(Server.MapPath("~/temp"), fileName);
using (MemoryStream stream = new MemoryStream())
{
// Start a new workbook
XLWorkbook wb = new XLWorkbook();
// Add a DataTable as a worksheet
var ws = wb.Worksheets.Add(dataTable, "MagicButton");
//wb.SaveAs(stream, false);
wb.SaveAs(fullPath);
return Json(new { fileName = fullPath, errorMessage = "" });
// Return a byte array
//return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "YourReportName.xlsx");
}