Text in cells issue

Hi support,

Please check the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.startTable();
builder.insertCell();
for (int i = 0; i < 100; ++i)
{
    builder.write("x");
}
builder.insertCell();
for (int i = 0; i < 100; ++i)
{
    builder.write("y");
}
builder.endRow();
builder.endTable();
doc.save("C:\Temp\docTextInTables.doc");

Note that in the output, the text in 1st cell goes out of page. If you create a new blank document, by using MS-Word, and if you press and hold a character key in an empty table cell, when the cursor gets near to the right page margin, it automatically jumps to a next line in cell. So, Word knows to break the text that hasn’t spaces in order to fit it in the cell. How can this be possible with aspose.word for java ?
Regards,
Milan

Hi
Thanks for your request. You should set width of each cell. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup ps = builder.getPageSetup();
builder.getCellFormat().setWidth((ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin()) / 2);
builder.getRowFormat().setAllowAutoFit(false);
builder.startTable();
builder.insertCell();
for (int i = 0; i < 100; ++i)
{
    builder.write("x");
}
builder.insertCell();
for (int i = 0; i < 100; ++i)
{
    builder.write("y");
}
builder.endRow();
builder.endTable();
doc.save("C:\\Temp\\docTextInTables.doc");

Hope this helps.
Best regards.