Convert HTML table to Excel spreadsheet without saving on server

Elerium HTML to Excel .NET component, new release 1.5 has been introduced by Elerium Software
 
June 7, 2013 - PRLog -- Very often, the .NET developer faces the task of processing the data presented in the form of HTML tables. Of course, it is most convenient tabular data processing, translating them into a special format such as the Excel format. A special converter by Elerium Software is designed to simplify and automate this task.

Elerium HTML to Excel .NET component, new release 1.5 has been introduced by Elerium Software. It has several important changes:
- Extended the parser list of CSS styles.
- Fixed bugs in Merged Cells.
- The algorithm was tested & optimized for big HTML tables.

How to use the component? First of all, a developer must install component to the project:
1. Add Elerium Excel .Net component to the solution. Simply put HtmlToExcel.dll into /bin folder of the project.
2. Initialize the Docs.HTML, Docs.Excel and Docs.Excel.Converting instance.

When the component is connected to the project a developer can convert HTML document to Excel spreadsheet and save it as a file or memory stream. The saving to memory stream is very convenient if is necessary to send the resulting file to the user without saving it on the server. This example shows how to convert HTML document to Excel as a memory stream:

C# code:

// Read the specified html file.
HtmlDoc html = HtmlDoc.ReadHTML(@"Html_to_Excel.html");
// Convert Html table to Excel
HtmlToExcel htmlexcel = new HtmlToExcel();
ExcelWorkbook excel = htmlexcel.Convert(html);
//Add text and save Excel file to Memory stream.
excel.Worksheets[0].Cells["C1"].Value = "HTML to Excel";
MemoryStream mstream = excel.WriteXLSX();

Let’s consider the practical application. Send the resulting file to the user into the browser window:

C# code:

// Read the specified html file.
HtmlDoc html = HtmlDoc.ReadHTML(@"Html_to_Excel.html");
// Convert Html table to Excel
HtmlToExcel htmlexcel = new HtmlToExcel();
ExcelWorkbook excel = htmlexcel.Convert(html);
// XLS
// Save Excel Workbook (XLS) to MemoryStream
byte[] bytes = excel.WriteXLS().ToArray();
// Show Excel (XLS) in Browser window without saving on disk
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
// XLSX
// Save Excel Workbook (XLSX) to MemoryStream
byte[] bytes = excel.WriteXLSX().ToArray();
// Show Excel (XLSX) in Browser window without saving on disk
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();

Also the professional version of the component allows to edit the Excel file before saving:

C# code:

/ Read the specified html file
HtmlDoc html = HtmlDoc.ReadHTML(@"Html_to_Excel.html");
// Convert Html table to Excel
HtmlToExcel htmlexcel = new HtmlToExcel();
ExcelWorkbook excel = htmlexcel.Convert(html);
// Change font style of first column
excel.Worksheets[0].Columns[0].Style.Font.Bold = true;
// Save Excel file as XLSX
MemoryStream mstream = excel.WriteXLSX();

About Elerium Software

Elerium Software develops professional solutions for use in .NET projects (C#, VB.NET, ASP.NET) that aimed to read/write/convert different office/web documents and formats. Elerium Software components are based on the unique design and fast algorithms that allow being independent from the third-party applications and libraries.

For more information about the component please visit the product page:
http://eleriumsoft.com/Excel_NET/Excel2HTML/Default.aspx
End
Source: » Follow
Email:***@eleriumsoft.com Email Verified
Tags:HTML to Excel, Excel, Net, Convert, c
Industry:Computers, Software
Location:luzern - Switzerland
Account Email Address Verified     Account Phone Number Verified     Disclaimer     Report Abuse
Elerium Software PRs
Trending News
Most Viewed
Top Daily News



Like PRLog?
9K2K1K
Click to Share