Hi, I am trying to set table cell margins in aspose. Could you please help asap. I also want the checkbox ''Same as the whole table" ticked as well. And the top, left , bottom, right values to be set to 0.05cm.
@usman.khan You can specify individual cell paddings using CellFormat properties BottomPadding, TopPadding, LeftPadding and RightPadding. us using CellFormat.SetPaddings method.
If you need the whole table use the same cell paddings you should set them using the appropriate properties of Table: BottomPadding, LeftPadding, RightPadding and TopPadding.
Hi @alexey.noskov,
Thanks for the quick response. I am already setting the table paddings
table.TopPadding = Convert.ToDouble(CellPadding);
table.BottomPadding = Convert.ToDouble(CellPadding);
table.RightPadding = Convert.ToDouble(CellPadding);
table.LeftPadding = Convert.ToDouble(CellPadding);
Now, using
builder.CellFormat.SetPaddings(CellPadding,CellPadding,CellPadding,CellPadding);
It sets the margins to 0.06 . For the same table padding value , it sets it to 0.05 cm which is what I want for cell margins as well.
I am using
private const float CellPadding = 1.4173228346f; //Equivalent to 0.05 cm
Here’s what it set up in the cell margins.
For table padding
Could you please help here. I also need that tickbox to be ticked too in cell margins. Without that, i am lost
Hi @alexey.noskov ,
Just an update : by doing it on individual cells , I am able to set it to 0.05 cm. So, that’s great. Thanks for helping with that.
All I need now is to find a way to tick this box. Could you please let me know if there’s a way to tick it on aspose.
Thanks
@usman.khan There is no a separate option to enable this checkbox, it is checked when paddings are inherited from the table. For example see the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
builder.InsertCell();
}
builder.EndRow();
}
builder.EndTable();
table.TopPadding = ConvertUtil.MillimeterToPoint(0.5);
table.BottomPadding = ConvertUtil.MillimeterToPoint(0.5);
table.RightPadding = ConvertUtil.MillimeterToPoint(0.5);
table.LeftPadding = ConvertUtil.MillimeterToPoint(0.5);
doc.Save(@"C:\Temp\out.docx");
Thanks @alexey.noskov for the above code. But its not working for me. May be because I am not creating the table in Aspose. I am setting properties on the already existed table in the word document, which came from EXCEL.
Please let me know if there’s any other way to set it up. Thanks.
@usman.khan Could you please attach your sample input document here for testing? We will check it and provide you more information. Most likely, the table already have cell padding set for each individual cell so cell paddings set on the table level are not inherited.
Hi @alexey.noskov , that would be a bit difficult to extract the code out of the main project and create sample project as its quite massive. I also can’t share the document itself since its official document.
However, I ll create the test project and sample document and share both with you but that would take some time . Please bare with me. I ll get back to in couple of days.