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

Free Support Forum - aspose.com

[Solved] Problem getting Table Cell Margins

Hi Aspose Team,

I am currently working with the last version of Aspose Words 13.3.0.1

I created a document containing a table using MS Word 2010.
Then using aspose words I want to resize the image inside the table to fit the cell.

My problem is that I cannot get the margins of the cell.
I use the following methods:

cell.getCellFormat().getLeftPadding();
cell.getCellFormat().getRightPadding();

But they return 0.
In MS Word the margins values are 5,4 pts.

Is there a way to get the margins value as in MS Word ?

Thanks.

Hi Edith,


Thanks for your inquiry.

The Shape actually resides in second Cell of first Row in your document. This Cell does not has any margin settings applied to it. However, you can set margins by using the following code snippet:
Document doc = new Document(“C:\Temp\TestTables.doc”);

Table tab = doc.getFirstSection().getBody().getTables().get(0);
Cell cell = tab.getFirstRow().getCells().get(1);

cell.getCellFormat().setLeftPadding(572);
cell.getCellFormat().setRightPadding(4
72);

doc.save(“C:\Temp\out.doc”);

Secondly, you can resize the image inside the table to fit the cell by using the following code snippet:
Document doc = new Document(“C:\Temp\TestTables.doc”);

Shape shape = (Shape)doc.getChildNodes(NodeType.SHAPE, true).get(0);

Cell c = (Cell) shape.getAncestor(NodeType.CELL);
shape.setWidth(c.getCellFormat().getWidth());
//shape.setHeight(c.getParentRow().getRowFormat().getHeight());

doc.save(“C:\Temp\out.doc”);

I hope, this helps.

Best regards,

Thanks for your answer.

Getting the shape and resizing it works great, when I define the cell margins or table margins:



Document doc = new Document(“C:\Temp\TestTables.doc”);



Table tab = doc.getFirstSection().getBody().getTables().get(0);



tab.setLeftPadding(13);

tab.setRightPadding(13);



Shape shape = (Shape)doc.getChildNodes(NodeType.SHAPE, true).get(0);



Cell c = (Cell) shape.getAncestor(NodeType.CELL);

shape.setWidth(cell.getCellFormat().getWidth() - cell.getCellFormat().getLeftPadding() - cell.getCellFormat().getRightPadding());



doc.save(“C:\Temp\out.doc”);





But I don’t want to set the margins I just want get the existing margins.



The problem is that MS Words tells me that the left and right table margins are 5.4 and Aspose Words tells me that it is 0.

Aspose Words should return the same value as MS Word when no margins are set.



Regards.

Hi Edith,

Thanks for your inquiry. I am afraid, I could not see any left/right margins for Table/Cell in your input document in Microsoft Word application; could you please clarify where the issue is? Please create and attach a screenshot highlighting/identifying the problematic areas in Microsoft Word here for testing.

Best regards,

Hi,



In MS Word I see that the table left and right margins are 5.4 pts. To view this go to the table properties dialog, and click the options… button on the bottom right of the dialog.

See the tableMargins.png attachment.



Now using Aspose Words to get the left and right margins of the table:



Document doc = new Document(“C:\Temp\TestTables.doc”);



Table tab = doc.getFirstSection().getBody().getTables().get(0);



System.out.println(tab.getLeftPadding());

System.out.println(tab.getRightPadding());



It outputs:

0

0



I hope I made myself clear.



Regards.

Hi Edith,

Thanks for the additional information.

While using the latest version of Aspose.Words i.e. 13.3.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-8116. Your request has also been linked to this issue and you will be notified as soon as it is resolved.

Sorry for the inconvenience.

Best regards,

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


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