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

Free Support Forum - aspose.com

Cell merge Horisontal doesn't work

Hi

I trie to extract text from a table where there are two merged cell horizontally, byt the aspose doesn't detect them, however the vertical one is detected.

I attached the file with my message so you can try it.

Could you please explain why it doesn't work?

Regards

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

Thanks for your inquiry. By Microsoft Word design rows in a table in a Microsoft Word document are completely independent. It means 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 has 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.

Best regards.

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

Actually what I did is the following:

In the word document that I sent to you, I selected two cells in the table and I merged them horizontally , and other two cells and I merged them vertically as you can see in the attached document, and I tried to extract them using DocumentVisitor. Aspose detect the vertical merged cells but it doesn’t detect the horizontal one. So I don’t understand when it’s considered horizontally merged?

Best regards

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

Thanks for your request. When you merge cells horizontally, MS Word merge these cells to a single simply wide cell. For example is you have a table like the following:

1, 1

1, 2

1, 3

2, 1

2, 2

2, 3

If you merge for example first two cells horizontally you will get the following result

1, 1

1, 2

2, 1

2, 2

2, 3

I mean that first row now contains only 2 cells, first cell is not merged cell, it is simply wide cell. But it looks like merged cell.

If you need you can open your document using DocumentExplorer (a sample Aspose.Words allication) to manage document structure.

Best regards.

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

Ok, you say that the two merged horizontally cells are not considered merged, so at what time it’s considered horizontally merged?

Send please an example.

Thanks

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

Thanks for your inquiry. The following code demonstrates what I mean.

//Create document and document builder.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Set default width of table cell

builder.CellFormat.Width = 50;

//Create first table with merged cells

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.InsertCell();

builder.CellFormat.HorizontalMerge = CellMerge.None;

//End first row

builder.EndRow();

builder.InsertCell();

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.EndTable();

builder.Writeln();

//Build another table that will look as the previouse one

//But first row will contain only two cells

//First cell will look like merged but it is simply wide

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.InsertCell();

builder.CellFormat.Width = 50;

//End first row

builder.EndRow();

builder.InsertCell();

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.EndTable();

//Save output document

doc.Save(@"Test070\out.doc");

If you open this document using DocumentExplorer you will see that the first row of the first table contains three cells but the first row of the second table contains only two cells. However, both tables look the same in MS Word.

Best regards.

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

If I understood you well, you meant that there is no way to detect two or more cells merged horizontally if the document was created by MS word, however we can detect them if the document was created by Aspose.words using CellMerge.First and CellMerge.previous?

Why the text in the second Cell is hidden when you open the file by MS Word?

Here is the code:

//Create document and document builder.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Set default width of table cell

builder.CellFormat.Width = 50;

//Create first table with merged cells

builder.InsertCell();

builder.Writeln("row1 cell1");

builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First;

builder.InsertCell();

builder.Writeln("row1 cell2");

builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.Previous;

builder.InsertCell();

builder.Writeln("row1 cell3");

builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;

//End first row

builder.EndRow();

builder.InsertCell();

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.EndTable();

builder.Writeln();

Regards

Hi

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

Thanks for your inquiry. There is an issue regarding this problem.

Issue #5367 - Merge content of cells during merging cells together.

Currently, you should insert content into the first of merged cells. If you merge cells in the existing table, you can use the following code to merge its content:

tab.FirstRow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;

//Move all content from next cell to praviouse

foreach (Node child in tab.FirstRow.Cells[1].ChildNodes)

{

tab.FirstRow.Cells[0].AppendChild(child);

}

tab.FirstRow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

Best regards.