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

Free Support Forum - aspose.com

Horizontal Alignment in a Table Cell

I have a table where the first cell should be left justified (horizontally) and the 2nd cell should be CENTER aligned. I can't get it to work. I have tried the following line:

builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT); for the first cell insert and changed it to CENTER for the 2nd cell insert. Both cells end up as CENTER aligned.

Can anyone help me with this problem. As far as I can see from the API help file there is no horizontal alignment property for a cell.

Thanks Richard

Hello

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

Thanks for your inquiry. You should set alignment of paragraph. Please see the following code:

//Create Docuemnt and Docuentbuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Set width of cells

builder.getCellFormat().setWidth(100);

//Start table

builder.startTable();

//insert cell

builder.insertCell();

//Set paragraph alignment

builder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);

//Insert text

builder.write("Right");

//Insert another cell

builder.insertCell();

builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);

builder.write("Left");

//And one more cell

builder.insertCell();

builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

builder.write("Center");

builder.endRow();

builder.endTable();

//Save output document

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

Hope this helps.

Best regards,