Hi Team ,
We are trying to convert HTML Table into excel , using below code.
There is no error in conversion but excel output is distorted and/or some table information is lost. e.g italic font.
You can replicate Issue using below :
Java Version : 1.8.0_51
Note : We have license for below version.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>18.4</version>
</dependency>
Java Code :
import com.aspose.cells.HTMLLoadOptions;
import com.aspose.cells.License;
import com.aspose.cells.LoadFormat;
import com.aspose.cells.Workbook;
import org.springframework.core.io.ClassPathResource;
import java.io.ByteArrayInputStream;
public class Test
{
public static void main(String args[]) throws Exception
{
String reportHTML = " <table width=“100%” style=" font-style:italic; font-family: Calibri; font-size: 10pt; border-spacing: 1px; border: 1px solid blue;">\n" +
“<tr>\n” +
" <td>\n" +
“<table width=“100%” style=“font-style:italic; font-family: Calibri; font-size: 10pt; border-spacing: 1px; border: 1px solid blue;”>\n” +
" <thead style=“font-family: Calibri; font-size: 10pt; border-spacing: 1px; border: 1px solid red;”>\n" +
" <tr>\n" +
" <th style=“border: 1px solid rgb(191, 191, 191);”>Table Header 1 </th>\n" +
" <th style=“border: 1px solid rgb(191, 191, 191);”>Table Header 2 </th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 1</td>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 2</td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 3 </td>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 4</td>\n" +
" </tr> \n" +
" </tbody>\n" +
“</table>\n” +
" </td>\n" +
" <td>\n" +
“<table width=“100%” style=“font-style:normal; font-family: Calibri; font-size: 10pt; border-spacing: 1px; border: 1px solid blue;”>\n” +
" <thead style=“font-family: Calibri; font-size: 10pt; border-spacing: 1px; border: 1px solid red;”>\n" +
" <tr>\n" +
" <th style=“border: 1px solid rgb(191, 191, 191);”>Table Header 11 </th>\n" +
" <th style=“border: 1px solid rgb(191, 191, 191);”>Table Header 22 </th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 11</td>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 22</td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 33 </td>\n" +
" <td style=“border: 1px solid rgb(191, 191, 191);”>Table cell 44</td>\n" +
" </tr> \n" +
" </tbody>\n" +
“</table>\n” +
" </td>\n" +
“</tr>\n” +
"</table> ";
License license = new License();
license.setLicense(new ClassPathResource(“Aspose.Cell.lic”).getInputStream());
HTMLLoadOptions loadOptions = new HTMLLoadOptions(LoadFormat.HTML);
loadOptions.setSupportDivTag(true);
ByteArrayInputStream bais = new ByteArrayInputStream(reportHTML.getBytes());
Workbook workbook = new Workbook(bais, loadOptions);
workbook.getWorksheets().get(0).autoFitColumns();
workbook.save(“D:\Downloads\output.xlsx”);
}
}
Kindly revert in case any more information is required.