NameSpace :
using System.Web.Hosting;
using ClosedXML.Excel;
[MTAThread]
private void ExportDataSetToExcel(DataSet ds, String excelName)
{
string path = HostingEnvironment.MapPath("~/FolderName/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + excelName;
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(ds.Tables[0]);
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.SaveAs(path, false);
}
}
Example:
DataSet objds = new Dataset();
ExportDataSetToExcel(objds, "FileName.xlsx");
Thank you sir G it is more useful for us
ReplyDelete