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

Free Support Forum - aspose.com

How to specify width of column in Word document from Java

Hi All,

I need help related to aspose words.

We have been using aspose words for past two years and your way of support is too good.

My query is related to Java with aspose words.

I am trying to create a table in word document using document builder.

But, how can I specify the width of row and width of cell.

builder.startTable();

After that what I need to specify to create a specific width table or default width of word document.

Please reply as soon as possible.

Thanks

Madhu Kiran

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. By Microsoft Word design rows in a table in a Microsoft Word document are completely independent. It means each row can have any number of cells of any width. So, please see the following code example:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);

builder.insertCell();

builder.getCellFormat().setWidth(200);

builder.write("Single cell");

builder.insertCell();

builder.getCellFormat().setWidth(300);

builder.write("3 span");

builder.endRow();

builder.insertCell();

builder.getCellFormat().setWidth(200);

builder.insertCell();

builder.getCellFormat().setWidth(100);

builder.insertCell();

builder.getCellFormat().setWidth(100);

builder.insertCell();

builder.getCellFormat().setWidth(100);

builder.endRow();

builder.endTable();

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,