Free Support Forum -

Text not splitted into 2 lines in result of converting to HTML


I am using Aspose Cells 17.8 to convert Excel files to HTML format.

Here is my code for test:

String fileName = “施工預定進度表及要逕圖.xls”;

Workbook book = new Workbook("custom/input/xlsx/" + fileName);
    new File("custom/output/xlsx/" + fileName + "/").mkdirs();

for (int page = 0; page < book.getWorksheets().getCount(); page++) {

//addHeader(book, page + 1, new ArrayList<Integer>());
ByteArrayOutputStream baos = new ByteArrayOutputStream();

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
	if (i == page) {
for (int i = 0; i < book.getWorksheets().getCount(); i++) {
	if (i != page) {

HtmlSaveOptions saveOps = new HtmlSaveOptions();

saveOps.setStreamProvider(new IStreamProvider() {

	public void initStream(StreamProviderOptions arg0) throws Exception {
		arg0.setStream(new ByteArrayOutputStream());

	public void closeStream(StreamProviderOptions arg0) throws Exception {
		OutputStream stream = arg0.getStream();
		if (stream instanceof ByteArrayOutputStream) {
			ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
					new FileOutputStream("custom/output/xlsx/" + arg0.getDefaultPath()));
});, saveOps);
		new FileOutputStream("custom/output/xlsx/" + fileName + "/" + (page + 1) + ".html"));


In the result of this Excel file, the text in B4 should be splitted into 2 lines in the result just like the origin, but it was not. (15.9 KB)
施工預定進度表及要逕圖 (6.7 KB)
image.jpg (71.6 KB)
Please check the attachment, and this issue.
Thank you~


Thanks for the template file(s) and sample code.

This is not an issue with the product rather it is the limitation of MS Excel, Aspose.Cells follows MS Excel standards and specifications when rendering to HTML/PDF. You may confirm this by opening the template Excel file into MS Excel and save it as “Web page”. Now open the HTML file into browse and you will that text is also not splitted into two lines.

Thank you.



Thanks for your reply.
There is some question I would like to ask:

  1. Is there some way to detect a cell like B4 if the text of it exceeded the edge,
    and then change the behavior of the cell, making the text of the cell wrap to lines in the result?

  2. In this Excel file, the text of the cells, like Q9, exceeded the edge of the its cell. The text of Q9 in the result generated by Aspose also exceeded of its edge. However the black grid lines of Q9, R9, S9, T9, U9, V9 are rendered out in the result. Is there some way not to render this grid lines, making it like what you see it in the MS Excel?


  1. I am not sure if there could be any better way to cope with it. I think you may try to create a Style object, set wrapped text on and then apply the style to the specified cell (you may auto-fit row/column to extend it accordingly). I will still check with the concerned developer if there is any option available for it and will get back to if I find any.

  2. Well, I think you may try to apply auto-fit column operation on the specified columns (e.g Q9) before rendering to HTML to make the gridlines off.

Thank you.



About 2.

Can we determine if a column needs to be applied with auto-fit programmatically?,

Well, I am afraid there is no proper way to do this. We do provide a method, i.e., Cell.GetWidthOfValue() to check the rough width needed by the cell value, so you may use this method to detect the width for all cells in one column, but it is not very inefficient approach.
You can compare the width with what you get with Cells.GetColumnWidth() for the particular column. So, if it is greater/less than column’s width, you may decide if it needs auto-fit operation for the particular column or not.
Mind you, GetColumnWidth will just give you rough width, not the exact same with the actual width required for auto-fit.