We found a lot of cases that the mail merge would fail for the template which contains 4 layers of nested tables and many nested conditional statements, even the data set for merging is small.
We are looking for a complexity measurement of a word template, so we could detect those templates and prevent our merging server from crashing.
I am not sure if Aspose library contains this kind of measurement API, or is there a solution for us to measure a word template?
We can calculate the layers of nested tables, but how can I calculate the layer number of nested conditional statements?
First you need to check how much time your code takes to fetch the data for mail merge region. Secondly, you need to remove unnecessary regions from the template. Your template document contains 11 regions. Please merge regions that have one-to-one relationship between tables.
Your document contains include picture fields using web link. If the links are same, please update this field after mail merge.
If you are generating document for huge number of records, it will take time. Please check at your end either Document.Save takes time or mail merge with region. We suggest you please use the latest version of Aspose.Words for .NET 20.4. Hope this helps you.
Actually, it would fail even for small data size. The time of fetching the data for mail merge could be ignored compared to the time spent on merging a document.
The template is from our tenant, we are not able to ask them to fix the template if we can’t measure the complexity automatically. That’s why I need to understand which kind of template would lead to terrible performance.
Secondly, you need to remove unnecessary regions from the template. Your template document contains 11 regions.
I can’t tell which regions are unnecessary because the template belongs to our tenants.
Please merge regions that have one-to-one relationship between tables.
I am not sure if I understand it. The tables here, do you mean MS Word Table, or data table in DB?
I would like to ask some questions to use Aspose effectively:
Would the number of regions or the number of nested regions have more impact on the rendering time?
Would many If fields in regions degrade the performance a lot?
You said the template contains 11 regions, but why I got the 15 regions through DocumentVisitor. There are two groups of 4-layers nested table(TaxItem_1, TaxItem_3, TaxItem_4, TaxItem_2) in the table TaxItem, but I can see only one 4-layers nested table from the Word document.
public class DocumentVisitor extends com.aspose.words.DocumentVisitor {
@Override public int visitFieldStart(FieldStart fieldStart) throws Exception {
final Field field = fieldStart.getField();
switch (field.getType()) {
case FieldType.FIELD_MERGE_FIELD:
final String fieldCode = field.getFieldCode(false);
if (fieldCode.contains("TableStart") || fieldCode.contains("TableEnd")) {
System.out.println(fieldCode);
}
break;
default:
break;
}
return super.visitFieldStart(fieldStart);
}
If you add many regions and IF fields in the document, the document gets complex.
Please note that performance hardly depends on local environment. It can be completely different for a server that generates thousands documents 24/7 or for a local PC that generate only the one document by demand.
If you are loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.
We suggest you please use SaveOptions.MemoryOptimization property to optimize the memory performance. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time. Hope this helps you.
If you still face problem, please attach the following resources here for testing:
Your input Word document.
Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.
Thank you. I will collect the resources you need.
The last question is why I got 15 regions through the DocumentVisitor. It seems Aspose visited the tables (TaxItem_1, TaxItem_3, TaxItem_4, TaxItem_2) twice.
We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-20295. You will be notified via this forum thread once this issue is resolved.
We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-20295 . You will be notified via this forum thread once this issue is resolved.
Please let me know the pattern causing the problem if you figured out the root cause. We could ask our customers to avoid the patten before it’s resolved.
Thank you
Please note that the issue (WORDSNET-20295) is related to incorrect count of TableStart fields. For performance issue, please use the latest version of Aspose.Words for .NET 20.4. If you face incorrect output and performance issue, please share the detail for testing as requested in my old post.
It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-20295) as ‘Not a Bug’. Please use the following code example to get the correct regions.
Document doc = new Document(MyDir + "high-complexity.doc");
foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldMergeField)
{
if (field.GetFieldCode(false).Contains("TableStart"))
Console.WriteLine(field.GetFieldCode(false));
}
}
doc.Accept(new DocStructurePrinter());
public class DocStructurePrinter : DocumentVisitor
{
public override VisitorAction VisitFieldStart(FieldStart start)
{
if (fieldResultEndChar == null)
{
if (start.FieldType == FieldType.FieldMergeField)
{
FieldMergeField field = (FieldMergeField)start.GetField();
if (field.FieldName.StartsWith("TableStart") || field.FieldName.StartsWith("TableEnd"))
Console.WriteLine(field.FieldName);
}
}
return VisitorAction.Continue;
}
public override VisitorAction VisitFieldSeparator(FieldSeparator fieldSeparator)
{
if (fieldResultEndChar == null)
fieldResultEndChar = fieldSeparator.GetField().End;
return VisitorAction.Continue;
}
public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd)
{
if (fieldResultEndChar == fieldEnd)
fieldResultEndChar = null;
return VisitorAction.Continue;
}
private FieldEnd fieldResultEndChar;
}
You can create a template document with merge fields by using any Word editor application, like Microsoft Word. By using Word editor application, you can take the advantage of the visual interface to design unique layout official site