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

Free Support Forum - aspose.com

Cell width is always returning as 0

Team,

I am using Aspose latest version for document conversion. I have attached document with this post containing table . I am trying to get cell width of table using below api

Document doc = new Document(myDir + “input.docx”);
NodeList cellNodes = doc.selectNodes("//Cell");//No I18N
for(Cell cell : cellNodes){
double width = cell.getCellFormat().getBorders().getLeft().getLineWidth();
String color = cell.getCellFormat().getBorders().getTop().getColor().toString();
System.out.println(“Width ::” + width);
System.out.println(“Color ::” + color);
}

Its is always returning O and black color for all tables. But it is working fine for doc format.
Hi Anbu,

Thanks for your inquiry. In your document, the table style 'Light Grid Accent 5' is applied to table. Please see the attached image for detail. In this case, I suggest you please use the Document.expandTableStylesToDirectFormatting method. This method converts formatting specified in table styles into direct formatting on tables in the document.

Moreover, this method exists because Aspose.Words v 13.6.0 provides only limited support for table styles. This method might be useful when you load a DOCX or WordprocessingML document that contains tables formatted with table styles and you need to query formatting of tables, cells, paragraphs or text.


Document doc = new Document(MyDir + "input.docx");

NodeList<Cell> cellNodes = doc.selectNodes("//Cell");

for(Cell cell : cellNodes){

double width = cell.getCellFormat().getBorders().getLeft().getLineWidth();

String color = cell.getCellFormat().getBorders().getTop().getColor().toString();

System.out.println("Width ::" + width);

System.out.println("Color ::" + color);

System.out.println("Background Color ::" + cell.getCellFormat().getShading().getBackgroundPatternColor());

}

System.out.println("------------------------------------------");

// Expand table style formatting to direct formatting.

doc.expandTableStylesToDirectFormatting();

// Now print the cell shading after expanding table styles.

for(Cell cell : cellNodes){

double width = cell.getCellFormat().getBorders().getLeft().getLineWidth();

String color = cell.getCellFormat().getBorders().getTop().getColor().toString();

System.out.println("Width ::" + width);

System.out.println("Color ::" + color);

System.out.println("Background Color ::" + cell.getCellFormat().getShading().getBackgroundPatternColor());

}

doc.save(MyDir + "out.docx");

Please read following documentation links for your kind reference.

Hope this helps you. Please let us know if you have any more queries.