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

Free Support Forum - aspose.com

cell.getCellFormat().getHorizontalMerge doesn't work?

Hello

I am currently trying to use the cell.getCellFormat().getHorizontalMerge method, but it does look like it doesn’t work properly.

I created a table (empty) and want to get the horizontalmerge property of each cell (document is joined)

And, I do the following code, based on this page: http://www.aspose.com/docs/display/wordsjava/Working+with+Merged+Cells

for(Row row : table){
for(Cell cell : row){
System.out.println(cell.getCellFormat().getHorizontalMerge());
}
}

I get only 0s.
Or, the 1st and 2nd cells of the 1st row are merged. Same for 2nd and 3rd of the 2nd row.
I only get 4 cells in Aspose, so I guess merged cells are considered as a unique cell. But the information of this cell being merged should be given.

Actually, the method only returns 0

Thank you in advance for your assistance.

Jean Pascal Lim

Hi Jean ,


Thanks for your inquiry.

Please note that a table in MS Word is a set of independent rows. Each row has a set of cells independent on cells of other rows. So there is no logical “column” in a MS Word’s table. “The 1st column” is something like “a set of the 1st cells of each row in a table”.

For example, it’s possible to have a table where the 1st row consists of two cells: 2cm and 1cm and the 2nd row consists of different two cells: 1cm and 2cm of width.

It would be great if you please share what exact you want to achieve by using Aspose.Words. We will then provide you more information about your query along with code.

Hello !

Thank you for your answer.

I am aware about the fact that a table is made of rows and that columns don’t exist.
My point wasn’t about the columns nor the size of the cells. I am only talking about horizontal merging, which only concern cells on the same row if not mistaken.
I just want to get the information if a cell is the result of merged cells.

You provide a method cell.getCellFormat().getHorizontalMerge() which is supposed to return this information.
According to the help (http://www.aspose.com/docs/display/wordsjava/Working+with+Merged+Cells) about this feature, if I am right, here is what we should get :
- if the cell is not merged, the result is expected to be CellMerge.NONE = 0
- if the cell is merged and it’s the first cell, the result is expected to be CellMerge.FIRST = 1;
- if the cell is merged and it’s not the first cell, the result is expected to be CellMerge.PREVIOUS = 2;

In the document I provided as example, there are 2 merged cells (made of 2 cells). And the method only returns 0, aka CellMerge.NONE. Why ?

Jean Pascal Lim

Hi Jean ,


Thanks for your inquiry. Please try to merge the table’s cell by using Aspose.Words and check the CellMerge value. Please use the following code snippet to merge the table’s cell and check the CellMerge value.

In your document, It seem that you merge the table’s cell by using MS Word. MS Word do not merge the cells but set the cell width.

Please note that a table in MS Word is a set of independent rows. Each row has a set of cells independent on cells of other rows. So there is no logical “column” in a MS Word’s table. “The 1st column” is something like “a set of the 1st cells of each row in a table”.

For example, it’s possible to have a table where the 1st row consists of two cells: 2cm and 1cm and the 2nd row consists of different two cells: 1cm and 2cm of width.


Hope this answers your query. Please let us know if you have any more queries.

Document doc = new
Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertCell();

builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);

builder.write("Text in merged cells.");

builder.insertCell();

builder.getCellFormat().setVerticalMerge(CellMerge.NONE);

builder.write("Text in one cell");

builder.endRow();

builder.insertCell();

// This cell is vertically merged to the cell above and should be empty.

builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);

builder.insertCell();

builder.getCellFormat().setVerticalMerge(CellMerge.NONE);

builder.write("Text in another cell");

builder.endRow();

builder.endTable();

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