We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML table to Excel using Java - Aspose Cells

I am trying Aspose cells before our company buys this product. I am trying to export 2 tables from an html to ONE Excel sheet with TWO sheets (one table in each sheet).

So far I have not tried with multiple sheets. But I tried with the attached html and I am not getting exact fomatted text (bold, italic, strikeout, color etc) in excel.


Thanks for providing an archive containing template HTML file and output Excel file.

After an initial, I observed the issue as you mentioned by converting your sample HTML file to XLS file format. I found an issue with HTML table to Excel rendering. Certain formatted data/content is clipped.or are not rendered the same way as per original file. The reason might be as you are using a common HTML file and not using MS Excel oriented HTML file, so the result might not be the same.
Sample code:

Workbook workbook = new Workbook(“f:\files\new11.html”, new LoadOptions(LoadFormat.HTML));

I have logged a ticket with an id “CELLSJAVA-42256” for your issue. We will look into it soon.

By the way, if you could open your template HTML file into MS Excel and re-save it as “Web Page”. Now use this in the above code, it would work fine and as expected.

Thank you.

Good thing is that I got confirmation from my company to buy the production IF it fulfills our requirement.

My Requirement: I have to just pass one String which contains the html string while calling Aspose methods/API (NOT the path of xyz.html). I have 6 different tables which will be divided into 3 sheets in ONE excel And my out put should be exact as it is in html table including bold, italic, color, strike through, font size etc. I know back ground color is not possible. Also numbering is not possible. but at least it would be great if all numbering can come like this
1. something
2. something else

Example of ONE Table cell:
This Customer is black listed for below reasons.

  1. Not paid monthly payment
  2. Did not reply to email
Our customer relation officer tried to contact many time:
  • On Monday April 01
  • On Tuesday April 02


Thanks for your posting and considering Aspose.Cells.

Please spare us some time, we will look into your issue and help you asap.


Thanks for your posting and using Aspose.Cells.

Please check the following code. It generates the Excel file from HTML string directly. I have attached the output Excel file for your reference.

Besides, I have also attached the code file for your ease, because HTML string is quite large.

//Your HTML string
String strHtml = "<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en” “http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd”>\n<html xmlns:v=“urn:schemas-microsoft-com:vml”\nxmlns:o=“urn:schemas-microsoft-com:office:office”\nxmlns:x=“urn:schemas-microsoft-com:office:excel”\nxmlns=“http://www.w3.org/TR/REC-html40”>\n\n\n<meta http-equiv=Content-Type content=“text/html; charset=utf-8”>\n\n<meta name=Generator content="Aspose.Cell “>\n<link rel=File-List href=“p_files/filelist.xml”>\n<link rel=Edit-Time-Data href=“p_files/editdata.mso”>\n<link rel=OLE-Object-Data href=“p_files/oledata.mso”>\n\n\n\n\n\n\n\n\n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n<![if supportMisalignedColumns]>\n \n \n \n <![endif]>\n
<font class=“font18”>This Customer is <font class=“font20”>black listed<font class=“font18”> for below reasons.
<font class=“font19”>1. Not<font class=“font18”> paid <font class=“font21”>monthly payment
2. Did not reply to email
Our customer relation officer tried to contact many time:
On Monday April 01
<font class=“font18”>On <font class=“font19”>Tuesday<font class=“font18”> <font class=“font23”>April<font class=“font18”> <font class=“font24”>02

//Get byte array of string
byte[] btsHtml = strHtml.getBytes();

//Create byte array input stream from the byte array
ByteArrayInputStream baisHtml = new ByteArrayInputStream(btsHtml);

//Create html load options
HTMLLoadOptions opts = new HTMLLoadOptions();

//Create workbook from your HTML string
Workbook wb = new Workbook(baisHtml, opts);

//Save the workbook in output format
wb.save(dirPath + “outputHtmlString.xlsx”);

Thanks a lot for your quick reply. I see there are so many \n\n and you have put everything in one line. As I said I need to have multiple sheets. Here I am attaching one sample html. And I tried to have three sheets in on Excel and to put the tables in corresponding sheets. But I am getting wired err/exception.

So far I have see this is meeting my requirement gradually.

Thanks for your posting and using Aspose.Cells.

We are afraid, we will not support to import free html to multiple worksheets. You will have to implement it by following these steps.

1 - Split the source html into several parts.

2 - Import every html via Aspose.Cells.

3 - Combine all the files into single workbook via copying ranges or copying worksheets.

4 - After you have split the source file into three parts, you can use the following code to combine them.

Workbook f1 = new Workbook(dirPath + "file1.html");
Workbook f2 = new Workbook(dirPath + "file2.html");
Workbook f3 = new Workbook(dirPath + "file3.html");

int f2Index = f1.getWorksheets().add();
Worksheet f2Sheet = f1.getWorksheets().get(f2Index);

int f3Index = f1.getWorksheets().add();
Worksheet f3Sheet = f1.getWorksheets().get(f3Index);
f1.save(dirPath + "out.xlsx");

Thanks for the suggestion. I will try that. But before that I tried to covert one single tab into excel. which doesn’t give me expected output. Attached is the html. Note: I have fomatted text (bold, italic etc) in one single TD.


Thanks for your posting and using Aspose.Cells.

We are able to replicate the issue as you have described at our end. We will look into it and fix this issue if possible. Please spare us some time, (at the moment, our issue tracking system is down), we will log your ticket and update you asap.


Thanks for using Aspose.Cells.

We have logged your issue now for an investigation and for a fix, in our database.

This issue has been logged as

  • CELLSJAVA-42259 - HTML could not be converted to Excel file properly

Thanks Shakeel. Is there any update?


Thanks for your posting and using Aspose.Cells.

We are afraid there is no update for you at this moment regarding this issue i.e. CELLSJAVA-42259. However, we have logged your comment in our database against this issue and requested the product team to provide some fix or ETA for this issue. Once there is some news for you, we will update you asap by posting in this thread.
For your other issue i.e. CELLSJAVA-42256, this ticket is open and we will fix the issues in "new11.html" file.


Thanks for using Aspose.Cells.

For your issue

  • CELLSJAVA-42259 - HTML could not be converted to Excel file properly

We are working over this issue and we are hopeful that we will be able to provide you a fix before May 24, 2017. Once, there is some fix or other news for you, we will update you.


Thanks for using Aspose.Cells.

Please download and try the following latest fix: Aspose.Cells for Java (Latest Version) and let us know your feedback.
About CELLSJAVA-42256 and CELLSJAVA-42259, please use the following code to test it:

HTMLLoadOptions options = new HTMLLoadOptions();

Workbook workbook = null;

workbook = new Workbook(filePath + "new11.html", options);

workbook.save(filePath + "java42256.xlsx");

workbook = new Workbook(filePath + "Single_Tab.html", options);

workbook.save(filePath + "java42259.xlsx");

The issues you have found earlier (filed as CELLSJAVA-42259;CELLSJAVA-42256) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.