Free Support Forum - aspose.com

(Java-Aspose Words Api) Reading a table from a Word document

I´m trying to read a table from a Word document that have merged cells but I have some problems.
//////////////////////////////////Code//////////////////////////////
if(child.getNodeType() == NodeType.TABLE){

Table table=(Table)child;
final NodeCollection rows= table.getChildNodes();
for(int x=0;x<rows.getCount();x++){
Row row =(Row)rows.get(x);
final NodeCollection columns = row.getChildNodes();
for(int y=0;y<columns.getCount();y++){
Cell cell = (Cell)columns.get(y);
System.out.println(cell.getCellFormat().getHorizontalMerge());
}
}
}
//////////////////////////////////Code//////////////////////////////
The horizontal merge of every cell is 0 --> CellMerge.NONE constant.

I would like to know that is something wrong with that, or there is another way to know if every cell of a table has merged horizontally with others of the same row.

Thank you,
Samuel

I want to know if in each table of a Word document there are any cells spanning multiple Rows or Columns. It´s the main problem that I have.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. This is by design (by Microsoft Word design). Rows in a table in a Microsoft Word document are completely independent. I mean each row can have any number of cells of any width. So if you imagine first row with one wide cell and second row with two narrow cells, then looking at this document the cell in the first row will appear horizontally merged. But it is not a merged cell, it is just a single wide cell. Another perfectly valid scenario is when the first row has two cells. First cell hs CellMerge.First and second cell has CellMerge.Previous, in this case it is a merged cell. In both cases the visual appearance in MS Word is exactly the same. Both cases are valid. Sometimes MS Word (or other document writer) writes one somtimes another.

Best regards.

The thing is that I have a Word document that has not been created with Aspose. In this doc file I have created a table that have many cells that have rowspan or columnspan.
I want to read a Word document file in order to know when I have this special cases of rowspan and columnspan. The function to know when a cell has rowspan works correctly, but the function for the columnspan don´t show me when a cell has columnspan.

Thank you for your help,

Samuel.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

When you merge cells horizontally using MS Words then merged cells are represented as one cell but not as multiple merged cells. For example:

Source table

Table with merged cells

The first row of source table contains 2 cells but the first row of the second table contains only one cell, but width of this cell is 2*regularCellWidth

So I think you should check width of each cell in your table.

Best regards.