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

Free Support Forum - aspose.com

Changing a single cell's format in datatable being imported into pdf

I have a datatable that I have imported into pdf. I want to format a single cell within the datatable (which might be in row 6, column 4. Is there any way to do that on the fly? I have researched through your documentation and forums and have found no easy way to do it.

Example would be looping through the rows, and find that column 4 value is a total (for that particular row in the datatable), so I want to put a Top border on just that cell. - so the pdf printout would look like the data below:

xxxxx yyyyy zzzzz 04
aaaaa bbbb cccc 04
bbbbb ccccc dddd 05

ccccc ddddd eeeee 01
dddd eeeeee ffffffff 02

Hello Ray,

Thanks for using our products.

As per your requirement, you can exclusively specify the border information for a particular table cell. Please try using the following code line, if you need to set the border information of a 4th column in a row.

row1.Cells[3].Border = new BorderInfo((int)BorderSide.Top, 0.1F);

Please take a look over the complete code snippet and the resultant PDF that I've generated is in attachment. Please take a look.


//Instantiate a Pdf object by calling its empty constructor
DataTable dt = new DataTable("Employee");
dt.Columns.Add("Column 1", typeof(string));
dt.Columns.Add("Column 2", typeof(string));
dt.Columns.Add("Column 3", typeof(string));
dt.Columns.Add("Column 4", typeof(Int32));

//Add 2 rows into the DataTable object programmatically
DataRow dr = dt.NewRow();
dr[0] = "xxxxx";
dr[1] = "yyyyy";
dr[2] = "zzzzz";
dr[3] = 04;

dr = dt.NewRow();
dr[0] = "aaaaa";
dr[1] = "bbbb";
dr[2] = "cccc";
dr[3] = 04;

dr = dt.NewRow();
dr[0] = "bbbbb";
dr[1] = "ccccc";
dr[2] = "dddd";
dr[3] = 05;

dr = dt.NewRow();
dr[0] = "";
dr[1] = "";
dr[2] = "";
dr[3] = 13;

//Instantiate a Pdf instance
Pdf pdf1 = new Pdf();
//Create a section in the Pdf instance
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

//Create a Table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
//Add the Table object in the paragraphs collection of the section
//Set column widths of the table
tab1.ColumnWidths = "50 50 50 15";
//Import data into the Table object from the DataTable created above

//Get 4th row from the table
Aspose.Pdf.Row row1 = tab1.Rows[3];
// set the border information for the 4th column in 4th row
row1.Cells[3].Border = new BorderInfo((int)BorderSide.Top, 0.1F);

//Save the Pdf

I would also recommend you to visit the following link for more information on

In case it does not satisfy your requirement or you've any further query, please feel free to contact.