The Aspose.Cells HTML Converter for .NET Plugin is a powerful tool that allows developers to convert Excel files into clean, responsive HTML markup and import HTML content back into Excel workbooks. This plugin bridges the gap between Excel and HTML, making it ideal for web-based viewers, email reports, and CMS integrations.
Introduction
The Aspose.Cells HTML Converter for .NET Plugin is a versatile tool that enables developers to export Excel files to HTML and import HTML content back into Excel workbooks. This plugin facilitates seamless data interoperability between Excel and HTML formats, making it ideal for web-based viewers, email reports, and CMS integrations.
Key Features of Aspose.Cells HTML Converter
- Export Excel to HTML
- Convert entire workbooks or specific worksheets into clean, responsive HTML using the Excel to HTML Converter.
- Import HTML Content into Excel
- Load HTML strings or files and convert them into Excel workbooks with support for tables, formatting, and structure.
- Flexible HTML Rendering Options
- Control the output with
HtmlSaveOptions
, including handling hidden rows/columns, exporting worksheets individually or together, etc.
- Control the output with
- Stream-Based Input and Output
- Save or load HTML via memory streams for efficient data handling in web apps, APIs, or serverless environments.
- Broad Format Support
- Works with a wide range of formats: XLS, XLSX, XLSB, XLSM, XLTX, XLTM, HTML, and MHTML.
- Native .NET Integration
- Easily integrates with .NET Framework and .NET Core/6/7/8 projects using NuGet or direct assembly reference.
Getting Started with Aspose.Cells HTML Converter for .NET
Install Aspose.Cells for .NET
Use NuGet to add Aspose.Cells to your project:
$ dotnet add package Aspose.Cells
Excel to HTML Conversion
Export your Excel workbooks to clean HTML format.
Convert Excel File to HTML File
Workbook workbook = new Workbook("Book1.xlsx");
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
workbook.Save("output.html", options);
Export Excel File to HTML Stream (e.g., for web app)
Workbook workbook = new Workbook("Book1.xlsx");
using (MemoryStream stream = new MemoryStream())
{
workbook.Save(stream, SaveFormat.Html);
stream.Position = 0;
// Use the stream for web response, writing to file, etc.
}
HTML to Excel Conversion
Convert HTML files or raw markup back into an Excel workbook.
Load HTML Content from a File
HtmlLoadOptions loadOptions = new HtmlLoadOptions();
Workbook workbook = new Workbook("input.html", loadOptions);
workbook.Save("html_to_excel.xlsx");
Load HTML Content from a String
string html = "<html><body><table><tr><td>Product</td><td>Price</td></tr><tr><td>Pen</td><td>$1.99</td></tr></table></body></html>";
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
Workbook workbook = new Workbook(stream, new HtmlLoadOptions());
workbook.Save("html_string_to_excel.xlsx", SaveFormat.Xlsx);
}
Most Popular Scenarios
Convert Excel Worksheet to HTML for Web Use
Workbook workbook = new Workbook("report.xlsx");
HtmlSaveOptions options = new HtmlSaveOptions
{
ExportHiddenWorksheet = false,
ExportGridLines = true
};
workbook.Save("report.html", options);
Import Styled HTML Table into Excel
Workbook workbook = new Workbook("styled_table.html", new HtmlLoadOptions());
workbook.Save("styled_table.xlsx");
Best Practices for HTML Conversion
- Use
HtmlSaveOptions.ExportGridLines = true
to mimic the spreadsheet layout. - Preprocess Excel data to fit within browser-friendly dimensions.
- When importing, ensure the HTML is well-formed and uses table elements for optimal results.
- Save to a stream if you intend to serve HTML directly in web APIs or cloud functions.
Common Issues and Resolutions
Error | Solution |
---|---|
File not found | Ensure the input path is correct and file exists |
Unsupported format | Confirm the file is either an HTML or Excel-compatible format |
Missing styles in output HTML | Check HtmlSaveOptions and confirm formatting is retained |
Content not aligned in imported Excel | Use tables in HTML and avoid deeply nested DIVs |
With these capabilities, Aspose.Cells provides a powerful tool for converting Excel to HTML while ensuring that formatting is preserved, allowing for seamless integration and display across various platforms. You can also convert Excel to HTML with formatting to enhance user experience and visual appeal.
Conclusion
Aspose.Cells HTML Converter for .NET offers robust features for converting Excel files into clean HTML markup and importing HTML content back into Excel workbooks. This plugin is an essential tool for developers looking to bridge the gap between Excel and web-based applications, ensuring seamless data interoperability.