Hi,
We have purchased aspose.total for java license 3 weeks back. We are facing a problem while excel to HTML conversion , if an excel has not wrap words set in any column then not visible text goes missing when we convert excel to html.
I have attached excel file as well as the produced HTMl file as an attachment. Please respond to it ASAP.
Thanks,
Ajay
Hi Ajay,
Thank you for contacting Aspose support.
Aspose.Cells APIs renders the spreadsheets to HTML as they are displayed in the MS Excel application. You can handle this situation in two ways, whereas each approach displays the text differently.
Solution 1:
You may call the Worksheet’s autoFitColumns method to give the text more space to display by widening the column.
Java
Workbook book = new Workbook(myDir + “good.xlsx”);
book.getWorksheets().get(0).autoFitColumns();
book.save(myDir + “output.html”, SaveFormat.HTML);
Solution 2:
You may also wrap the text in a particular cell which is cutting off while rendering the spreadsheet to HTML. In this case, the text will wrap it self to display properly in the resultant HTML
Java
Workbook book = new Workbook(myDir + "good.xlsx");
int index = book.getStyles().add();
Style style = book.getStyles().get(index);
style.setTextWrapped(true);
book.getWorksheets().get(0).getCells().get("A1").setStyle(style);
book.save(myDir + "output.html", SaveFormat.HTML);
Hope this helps a bit.
Hi,
I tried the first option provided by you i.e. AutofitColumns but it autofits already wrapped columns. Is there any option that we autofit only those columns which are not wrapped? Or Do we have any option to wrap all the columns?
We are facing another issue that the HTML generated by the aspose.cells (java) contains too much javascript code inside it and the user is shown a unresponsive script popup.
Is there any way to reduce javascript inside HTML? Does this AutofitColumns option increase the scripts in the HTML?
I have attached the screenshot of with the reply.
Thanks,
Ajay
Hi Ajay,
Thank you for writing back.
You can auto fit a particular column by using the Worksheet.autoFitColumn(int column) method as per your requirement. Although the wrapped text property has limited scope of Style class, and a style can be applied to Column as well as Cell. Therefore if you wish to check if a particular column has wrapped text property enabled, you have to check its Style object for isTextWrapped property. Moreover, even though a Column as a whole may not have the wrapped text property enabled, but the cells in that column may have the aforesaid property set to true.
Here is how you may check if a Column has isTextWrapped property enabled or not.
Java
Workbook workbook = new Workbook(myDir + “good.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(0);
//Iterate all columns till the max data column
for (int i = 0 ; i < worksheet.getCells().getMaxDataColumn() ; i++)
{
//Get the column instance at a particular index from the column collection
Column column = worksheet.getCells().getColumns().get(i);
//Check if column does not have isTextWrapped property enabled
if(!column.getStyle().isTextWrapped())
{
worksheet.autoFitColumn(column.getIndex());
}
}
Regarding the other part of your inquiry, the JavaScript code injected in Aspose.Cells generated HTML basically deals with the interactive part of the webpage, like scrolling, mouse click/hover, worksheet tabs etc. I don’t think that more JavaScript code is added by just calling the
Worksheet.autoFitColumns method before rendering the spreadsheet to HTML format. Nor I was able to replicate the problem while using the FireFox, Chrome and IE 11 to render the HTML. We would request you to please give the latest version of
Aspose.Cells for Java (Latest Version) a try on your end to see if it makes any difference. In case the problem persists, please provide the input and output files in an archive along with your code snippets for our review.