@ashish29190,
We have further investigated the issue and would like to share that there is no other option available in Aspose.Cells which can be used to trim the undesired text from the Html file. However it is quite easy to extract pure table contents from the html file as follows:
private static void Cells_Html() throws Exception
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.getWorksheets().get(0);
// Adding sample values to cells
worksheet.getCells().get("A1").putValue(50);
worksheet.getCells().get("A2").putValue(100);
worksheet.getCells().get("A3").putValue(150);
worksheet.getCells().get("B1").putValue(60);
worksheet.getCells().get("B2").putValue(32);
worksheet.getCells().get("B3").putValue(50);
// Set the print area.
worksheet.getPageSetup().setPrintArea("A1:B3");
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setExportHiddenWorksheet(false);
options.setExportImagesAsBase64(true);
options.setExcludeUnusedStyles(true);
options.setExportComments(false);
options.setExportDocumentProperties(false);
options.setExportWorkbookProperties(false);
options.setExportWorksheetProperties(false);
options.setDisableDownlevelRevealedComments(true);
//Save to HTML format
workbook.save("output.html", options);
String data=readFile("output_files\\sheet001.htm",Charset.defaultCharset());
String result = "<table"+ StringUtils.substringBetween(data, "<table", "</table>")+ "</table>";
System.out.println(result);
}
static String readFile(String path, Charset encoding) throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
Here is the program output:
<table border='0' cellpadding='0' cellspacing='0' width='128' style='border-collapse:
collapse;table-layout:fixed;width:96pt'>
<col width='64' span='2' style='width:48pt'>
<tr height='17' style='mso-height-source:userset;height:12.75pt' id='r0'>
<td height='17' width='64' align='right' x:num="50" style='text-align:right;height:12.75pt;width:48pt;'><a name="Print_Area" >50</a></td>
<td width='64' align='right' x:num="60" style='text-align:right;width:48pt;'>60</td>
</tr>
<tr height='17' style='mso-height-source:userset;height:12.75pt' id='r1'>
<td height='17' align='right' x:num="100" style='text-align:right;height:12.75pt;'>100</td>
<td align='right' x:num="32" style='text-align:right;'>32</td>
</tr>
<tr height='17' style='mso-height-source:userset;height:12.75pt' id='r2'>
<td height='17' align='right' x:num="150" style='text-align:right;height:12.75pt;'>150</td>
<td align='right' x:num="50" style='text-align:right;'>50</td>
</tr>
<tr height='0' style='display:none'>
<td width='64' style='width:48pt'></td>
<td width='64' style='width:48pt'></td>
</tr>
</table>