Zehra Subaş
Zehra Subaş

Reputation: 473

Giving zero indent for inner cell Indent in Aspose Word

I am trying to create inner cells in pdf with using aspose words. But I have issues about its style. I need to center and fit my text in cell. But when I set center property for cell it gives some padding automatically.

I made a sample with MS word as below image: enter image description here

This one is that I have created programmatically with using aspose words.enter image description here

As you can see it doesn't fit when I set center property true for columns. My inner cell import code is below:

Cell cell = table.Rows[j].Cells[i];
cell.CellFormat.RightPadding = 0;
foreach (Paragraph pf in cell.Paragraphs)
{
     pf.ParagraphFormat.LeftIndent = 0;
}
cell.CellFormat.WrapText = false;
builder.MoveTo(cell.FirstParagraph);

builder.InsertCell();
builder.Writeln(tr.Rows[j][i].Value);
builder.EndTable();

Which property should I set to fit it in cell, thanks.

Upvotes: 0

Views: 1243

Answers (1)

Tahir Manzoor
Tahir Manzoor

Reputation: 597

Please use following code example to get the required output. You may modify the table/cell width according to your requirement. I suggest you please read following link to work with tables. Hope this helps you.

Working with Tables

If you still face problem, share your input and expected output documents. I will share the code according to your expected document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Calibri";
builder.CellFormat.LeftPadding = 0;
builder.CellFormat.RightPadding = 0;
builder.CellFormat.TopPadding = 0;
builder.CellFormat.BottomPadding = 0;

Table table = builder.StartTable();

// Insert a cell
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(33);

//Insert inner table
Table table1 = builder.StartTable();
builder.InsertCell();
table1.Alignment = TableAlignment.Left;
table1.PreferredWidth = PreferredWidth.FromPercent(50);

builder.Write("This is cell 1");
builder.EndRow();
builder.EndTable();

// Insert a cell
builder.InsertCell();
//Insert inner table
Table table2 = builder.StartTable();
builder.InsertCell();
table2.Alignment = TableAlignment.Center;
table2.PreferredWidth = PreferredWidth.FromPercent(50);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("This is cell 2");
builder.EndRow();
builder.EndTable();

// Insert a cell
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(33);

//Insert inner table
Table table3 = builder.StartTable();
builder.InsertCell();
table3.PreferredWidth = PreferredWidth.FromPercent(50);
table3.Alignment = TableAlignment.Right;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.Write("This is cell 3");
builder.EndRow();
builder.EndTable();

builder.EndRow();
builder.EndTable();

doc.Save(MyDir + "Out.docx");

I work with Aspose as Developer evangelist.

Upvotes: 0

Related Questions