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

Free Support Forum - aspose.com

Table merge is not working properly

Hi ,

I am using aspose words . Table merge is not working properly when i setsetAllowAutoFit as “false” , but when i set setAllowAutoFit as “true” merge is working properly but table runs out of the editor . Please help me with the code .( Below i posted my code )

Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Table table = builder.startTable();
Cell cell1 = builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("Text in merged cells.");
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.endRow();
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.write("Text in one celldsssssssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsssssssssssssssssss.");
table.setAllowAutoFit(false);
builder.insertCell();
builder.write("Text in another cell.");
builder.endRow();
builder.endTable();

Hi Anbu,

Thanks for your inquiry. Please read about specifying table and cell width from here:
http://www.aspose.com/docs/display/wordsjava/Specifying+Table+and+Cell+Widths

Please use CellFormat.PreferredWidth as shown in following code example to achieve the required output. Hope this helps you. Please let us know if you have any more queries.

Document doc = **new** Document(); 
DocumentBuilder builder = **new** DocumentBuilder(doc); 
Table table = builder.startTable();
Cell cell1 = builder.insertCell();
table.setAllowAutoFit(**false**);
builder.getCellFormat().setPreferredWidth(PreferredWidth.*fromPoints*(ConvertUtil.*inchToPoint*(6)));
builder.getCellFormat().setHorizontalMerge(CellMerge.*FIRST*);
builder.write("Text in merged cells.");
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.*PREVIOUS*);
builder.endRow();
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.*fromPoints*(ConvertUtil.*inchToPoint*(3)));
builder.getCellFormat().setHorizontalMerge(CellMerge.*NONE*);
builder.write("Text in one celldsssssssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsssssssssssssssssss.");
builder.insertCell();
builder.write("Text in another cell.");
builder.endRow();
builder.endTable();
doc.save(*MyDir* + "Out.docx");

Hi Tahir ,

Thanks for the response . Merge is working properly when i set Preferred width in inches( " ) . But , what i have is percentage value and need to set autofit to window for the table , when i set preferred width in percent( % ) table merge not working . Please help me with it .

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
Cell cell1 = builder.insertCell();
table.setAllowAutoFit(false);
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(100));
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("Text in merged cells.");
builder.insertCell();
//builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(100));
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.endRow();
table.autoFit(AutoFitBehavior.AUTO\_FIT\_TO\_WINDOW); 
builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(50));
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.write("Text in one celldsssssssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsssssssssssssssssss.");
builder.insertCell();
// builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(50));
builder.write("Text in another cell.");
builder.endRow();
builder.endTable();

Hi Anbu,

Thanks for sharing the detail. I have tested the scenario and have managed to reproduce the same issues at my side. For the sake of correction, I have logged these problems in our issue tracking system as follow:

WORDSNET-11383 : Table.AllowAutoFit = false ignores the merged cell
WORDSJAVA-1004 : Table.setAllowAutoFit(true) moves the table outside the page

I have linked this forum thread to the same issues and you will be notified via this forum thread once these issue are resolved.

We apologize for your inconvenience.

Hi Anbu,

Thanks for your patience. It is to inform you that our product team has completed the analysis of issue (WORDSJAVA-1004)
and has come to a conclusion that this issue and the
undesired behavior you’re observing is actually not a bug in
Aspose.Words.

Please use Compatibility.GrowAutofit and Table.PreferredWidth properties as shown in following code example to get the required output.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
Cell cell1 = builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("Text in merged cells.");
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
builder.endRow();
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.write("Text in one celldsssssssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsssssssssssssssssss.");
builder.insertCell();
builder.write("Text in another cell.");
builder.endRow();
builder.endTable();
table.setAllowAutoFit(true);
doc.getCompatibilityOptions().setGrowAutofit(false);
table.setPreferredWidth(PreferredWidth.AUTO);
doc.save(*MyDir* + "Out.docx");

The issues you have found earlier (filed as WORDSNET-11383) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for .NET 18.12 update and this Aspose.Words for Java 18.12 update.