TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
rahul mane
1.6k
80
5.1k
i want to export html string to excel
Mar 21 2018 6:27 AM
we want to export html sting to excel in cell
my html string like
'<html>
<head>
<style> table {border - collapse: collapse;} table, td, th { border: 1px solid black;}</style>
</head>
<body>
<table width="678">
<tbody>
<tr>
<td width="128">
<p>11002264</p>
</td>
</tr>
<tr>
<td rowspan="3" width="128">
<p>08W10000004</p>
</td>
<td width="128">
<p>11002238</p>
</td>
</tr>
<tr>
<td width="128">
<p>11002252</p>
</td>
</tr>
<tr>
<td width="128">
<p>11002264</p>
</td>
</tr>
</tbody>
</table>
</body>
</html>'
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();
Reply
Answers (
2
)
web.config allowDefinition='MachineToApplication' app error.
How to send Confirmation mail to the registered user in MVC?