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

Free Support Forum - aspose.com

Table border

I want to apply table border only on row level.

I am trying below and it is not working

Document doc = new Document();
Table table = new Table(doc);
Row row = new Row(doc);
Cell tCell = new Cell(doc); 
tCell.getCellFormat().getBorders().setLineStyle(LineStyle.NONE);
row.appendChild(tCell);
row.getRowFormat().getBorders().setLineStyle(LineStyle.SINGLE);
row.getRowFormat().getBorders().setColor(Color.GRAY);
table.appendChild(row);

And this is not working. Can you please let me know the reason?

Hi Abhradeep,

Thanks for your inquiry. Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Actually I want to apply table border to some specific rows in the table. Docx doesn’t have the functionality to add row level border. But I saw aspose have api to add border row level that is why inquiring about that.

Hi Abhradeep,

Thanks for your
inquiry. Please read following article about applying borders and shading:
https://docs.aspose.com/words/java/applying-formatting/

Following code example shows how to set the top border of each cell. Hope this helps you. I have attached the input and output documents with this post for your kind reference.

Document doc = new Document(MyDir + "in.docx");
for (Cell cell : (Iterable)doc.getChildNodes(NodeType.CELL, true))
{
    cell.getCellFormat().getBorders().clearFormatting();
    cell.getCellFormat().getBorders().getTop().setLineStyle(LineStyle.SINGLE);
    cell.getCellFormat().getBorders().getTop().setLineWidth(2.0);
}
doc.save(MyDir + "Out.docx");

Please let us know if you have any more queries.