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

Free Support Forum - aspose.com

Setting Width for newly created Table

Hi,

I am using Aspose Words for java 10.2.0. I create a Table using the following code, the table cell width seems to be small.I want the table to be in width of page size. How to set the default width for the table.Please help me.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.removeAllChildren();

Body body = new Body(doc);
Section section = new Section(doc);
doc.appendChild(section);
section.appendChild(body);

CompositeNode latestBlock = body;
Paragraph currentPara = new Paragraph(doc);
Run currentRun = null;

currentPara = new Paragraph(doc);

latestBlock.appendChild(currentPara);
currentRun = new Run(doc, “Welcome to Home”);
currentPara.appendChild(currentRun);

builder.moveTo(currentPara);
Table table = new Table(doc);

Row row=new Row(doc);
table.appendChild(row);

Cell cell = new Cell(doc);
cell.appendChild(currentPara);

row.appendChild(cell);

latestBlock.appendChild(table);

doc.save(“src/Output.docx”);

Hi

Thanks for your request. There is no way to set width of whole table, but you can easily set width of a particular cell in the table:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/cellformat.html#Width

Also, I think the code provided here could be useful for you:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/howto-autofit-a-table-to-page-width.html

Best regards,