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

Free Support Forum - aspose.com

MailMerge and updateTableLayout problem

Hi

I am currently evaluating Aspose.Words for Java (v3.0.1) and stumbled upon a little, hum, let’s call it “unexpected behaviour”, most of which I could fix with several workarounds I found in this forum.

Unfortunately, an error affecting mail merges with merge fields inside a table occurs here, which - according to this thread - is somewhat older.
The situation is as follows: The template (see attached template.doc) contains a table with some columns that span several columns. The table contains the merge fields. If I do a default mail merge, the document produced looks fine. However, if I add a call to document.updateTableLayout(), then the spanning columns get resized to the first column of the table (see document.doc).

Because I have to additionally create Tables after the mail merge has been completed, I cannot omit this call: the new tables look completely wrong without this call.

Is there anything that can be done about this problem?

Thanks

Hi

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

Thanks for your inquiry. I managed to reproduce the problem and linked your request to the appropriate issue.

The problem occurs, because 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.

Our table layout algorithm does not like simply wide cells. That is why the problem occurs. As a workaround, you can try refactoring your template. If you need, I can help you to change your template. If so please provide me your e-mail and I will send you refactored document.

Best regards.

Hi

Yeah, I guessed something like that (Word’s rather strange internal model of what a table is in combination with your algorithm).
As I am no Word-superguru, I’d really like to know how to rework the template. e-mail address is underway via p/m.

Thanks

Hi

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

Actually, I did nothing in MS Word to refactor your document. I refactored it programmatically using the following code:

// Open document

Document doc = new Document("C:\\Temp\\template.doc");

// Get table

Table tab = doc.getFirstSection().getBody().getTables().get(0);

for(Row row : tab.getRows())

{

if(row.getCells().getCount() == 1)

{

// Add two more cells and merge them with existing cell

Cell cell = new Cell(doc);

cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);

row.getFirstCell().getCellFormat().setHorizontalMerge(CellMerge.FIRST);

row.appendChild(cell.deepClone(true));

row.appendChild(cell.deepClone(true));

}

}

// Update table layout

doc.updateTableLayout();

// Save output document

doc.save("C:\\Temp\\out.doc");

I sent the output document to your e-mail.

Best regards.

The issues you have found earlier (filed as WORDSNET-837) have been fixed in this Aspose.Words for .NET 22.2 update also available on NuGet.