Change Text of a cell

Hi,


I have created a method in which I need to change the text of a particular cell. I am passing Row object as input and getting the cell by its index.

Aspose.Pdf.Generator.Cell c = row.Cells[index - 1];

Above cell has already initialized and set with values. I need to change below properties -
1. Text
2. Column Align
3. Column Vertical Align

Ref- Aspose PDF.

Kindly help in the same.

Hi Ashis,


Thanks for contacting support.

In order to accomplish your requirement, please try using following code snippet based on

new Document Object Model of Aspose.Pdf namespace. For your reference, I have also attached the output generated over my end.

[C#]

//
Load source PDF document
<o:p></o:p>

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

doc.Pages.Add();

// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

// Set the table border color as LightGray

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// set the border for table cells

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// create a loop to add 10 rows

for (int row_count = 1; row_count < 10; row_count++)

{

// add row to table

Aspose.Pdf.Row row = table.Rows.Add();

// add table cells

row.Cells.Add("Column (" + row_count + ", 1)");

row.Cells.Add("Column (" + row_count + ", 2)");

row.Cells.Add("Column (" + row_count + ", 3)");

}

// set horizontal alignment of third cell in last row of table

table.Rows[8].Cells[2].Alignment = Aspose.Pdf.HorizontalAlignment.Center;

// set veritical alignment of table cell

table.Rows[8].Cells[2].VerticalAlignment = VerticalAlignment.Bottom;

// clear previous contents in table cell

table.Rows[8].Cells[2].Paragraphs.Clear();

// add new contents to table cell

table.Rows[8].Cells[2].Paragraphs.Add(new TextFragment("Hello World.."));

// Add table object to first page of input document

doc.Pages[1].Paragraphs.Add(table);

// Save updated document containing table object

doc.Save("c:/pdftest/document_with_table.pdf");