we want to export html sting to excel in cell
my html string like
'
11002264 | |
08W10000004 | 11002238 |
11002252 | |
11002264 |
'
currently i wrote this code
using (ExcelPackage exportPackge = new ExcelPackage())
{
String FileName = String.Empty;
FileName = "Report";
ExcelWorksheet exWorkSheet = exportPackge.Workbook.Worksheets.Add("Report");
DataTable ExcelData = null;
DataView view =getdata()
ExcelData = view.ToTable("Selected", false, "Value");
var customer = "Rahul ";
exWorkSheet.Cells["A1"].Value = "Report Generated On:";
exWorkSheet.Cells["A1"].Style.Font.Bold = true;
exWorkSheet.Cells["A1"].Style.Font.Size = 12;
exWorkSheet.Cells["B1"].Value = DateTime.Now.ToString("dd/MM/yyyy");
exWorkSheet.Cells["B1"].Style.Font.Size = 12;
exWorkSheet.Cells["A2"].Value = customer;
exWorkSheet.Cells["A2"].Style.Font.Bold = true;
exWorkSheet.Cells["A2"].Style.Font.Size = 12;
exWorkSheet.Cells["A5"].LoadFromDataTable(ExcelData, true);
exWorkSheet.Cells["A3"].Value = "ABS Report";
exWorkSheet.Cells["A3"].Style.Font.Bold = true;
exWorkSheet.Cells["A3"].Style.Font.Size = 12;
exWorkSheet.Cells["A3"].AutoFitColumns(50);
exWorkSheet.Cells["A5"].Style.Font.Bold = true;
exWorkSheet.Cells["A5"].Style.Font.Size = 12;
exWorkSheet.Cells["A5"].Value = "ABS";
exWorkSheet.Cells["A5"].AutoFitColumns(200);
using (ExcelRange col = exWorkSheet.Cells[5, 1, 5 + ExcelData.Rows.Count, 1])
{
col.Style.Numberformat.Format = "dd/MM/yyyy";
col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Justify;
col.Style.VerticalAlignment = ExcelVerticalAlignment.Top;
col.Style.WrapText = true;
col.Style.Border.Top.Style = ExcelBorderStyle.Thin;
col.Style.Border.Left.Style = ExcelBorderStyle.Thin;
col.Style.Border.Right.Style = ExcelBorderStyle.Thin;
col.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
}
Byte[] fileBytes = exportPackge.GetAsByteArray();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + FileName + ".xlsx");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(fileBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
Aniket RanaPosted Mar 22, 2018, 1:20 AM
Sagar Pandurang KapPosted Mar 21, 2018, 7:02 AM