Set Cell Individual Border

Hi All,

I want to set only Top and Right border of cell.

I have written following code

Aspose.Pdf.Generator.Table ltable = new Aspose.Pdf.Generator.Table();

Row lRow = new Row(ltable);

Cell lCell = new Cell(lRow);

GraphInfo lGrInfo1 = new GraphInfo();

lGrInfo1.GraphBorder = new BorderInfo((int)BorderSide.Top, 0.5f, new Aspose.Pdf.Generator.Color("#3354a5"));

lCell.Border.Top = lGrInfo1;

GraphInfo lGrInfo2 = new GraphInfo();

lGrInfo2.GraphBorder = new BorderInfo((int)BorderSide.Right, 0.5f, new Aspose.Pdf.Generator.Color("#3354a5"));

lCell.Border.Right= lGrInfo2;

Text lText = new Text("Test");

lText.TextInfo.Alignment = AlignmentType.Center;

lCell.Paragraphs.Add(lText);

lRow.Cells.Add(lCell);

ltable.Rows.Add(lRow);

It is throwing error on line --> 'lCell.Border.Top = lGrInfo;' that Object reference not set to an instance of an object.

But the property Cell.Border.Top says 'Gets or Sets GraphInfo object that indicates the top border'. But it is throwing error when I try to Set the property.

Please suggest how to set only required borders of cell asap.

Regards,

Hi Jagdish,

Thanks for using our products and sharing the sample source code.

I tested the scenario using your source code and able to notice the same problem. However, I have changed the code as mentioned below and unable to find any error. Kindly use the below code and check if it fits your need.

[C#]

Aspose.Pdf.Generator.Table ltable = new Aspose.Pdf.Generator.Table();<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Row lRow = new Row(ltable);

Cell lCell = new Cell(lRow);

GraphInfo lGrInfo1 = new GraphInfo();

BorderInfo leftBorder = new BorderInfo();

lGrInfo1.GraphBorder = new BorderInfo((int)BorderSide.Top, 0.5f, new Aspose.Pdf.Generator.Color("#3354a5"));

leftBorder.Left = lGrInfo1;

lCell.Border = leftBorder;

GraphInfo lGrInfo2 = new GraphInfo();

BorderInfo rightBorder = new BorderInfo();

lGrInfo2.GraphBorder = new BorderInfo((int)BorderSide.Right, 0.5f, new Aspose.Pdf.Generator.Color("#3354a5"));

rightBorder.Right = lGrInfo2;

lCell.Border = rightBorder;

Text lText = new Text("Test");

lText.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;

lCell.Paragraphs.Add(lText);

lRow.Cells.Add(lCell);

ltable.Rows.Add(lRow);


Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

So , it just has format at rightBorder , so leftBorder is not added in this !

Hi Valentino,


Thanks for contacting support.

Can you please share some further details regarding the issue that you are facing and also please share the source PDF file so that we can test the scenario at our end. We are sorry for your inconvenience.

Hi Nayyer ,


Thanks for reply my post .

Please see my post : <a href="https://forum.aspose.com/t/83924

Thanks you !
valentino_nguyen_26892:
Please see my post : 475354.