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

Free Support Forum - aspose.com

How many columns are possible for mail merge

Hi All,

how many columns can I set up for a mail merge.

Also: is there a limitation how long the field/column name can be.

Thanks in advance

Herbert

Hi,
isn’t there anybody who can help?
Regards
Herbert

Hi Herbert,

Thanks for your inquiry.

*HowieD_Dom:

how many columns can I set up for a mail merge.*

Please note that Aspose.Words mimics the same behavior as MS Word does. Please read this link for your kind reference.

It depends on the data source. Could you please share what kind of data source you want to use for mail merge? We will then provide you more information on this.

*HowieD_Dom:

Also: is there a limitation how long the field/column name can be.*

The mail merge field name’s length limit is 255. Please read this link for your kind reference.

Hi Tahir,

thank you for your answer.

We use a CSV File as data source. As far as I can see right now there is a limit of 255 fields for this source type. But I have to do some further invastigation since sometimes the field layout differs a little bit. Which leeds me to the question if the ordinal positions of the fields are saved in the template in any way?

The fieldname length is limited to somewhat around 40 charactes. Since when I do layout in Word fields with longer names are truncated. Leading to the problem that data would not be in the document after mail merge has taken place.

Looking forward to hear from you.

Best regards

Herbert

Hi Herbert,

Thanks for your inquiry.

*HowieD_Dom:

As far as I can see right now there is a limit of 255 fields for this source type. But I have to do some further investigation since sometimes the field layout differs a little bit. Which leeds me to the question if the ordinal positions of the fields are saved in the template in any way?*

Could you please share some more detail about this query? We will then provide you more information on this.

*HowieD_Dom:

The fieldname length is limited to somewhat around 40 characters. Since when I do layout in Word fields with longer names are truncated. Leading to the problem that data would not be in the document after mail merge has taken place.*

The mail merge field’s display text is 40 characters. Please press Alt + F9 to see the complete mail merge field name.

Hi Tahir,

currently it seems that I don’t have an issue with the number of columns in the data source. Attached you’ll find a file called TempMMData.csv which contains more than 300 fields right now.

Pressing Alt + F9 doesn’t show the complete fieldnames unfortunately. For this reason you’ll find the file Template Test 01.docx attached, which was entirely designed using Word 2010 (latest SP and fixes). In the template file you can see the files with the truncated name if you open it with an xml editor. After a subsequent mail merge the fields on the right side have no data (file MaiMerg Test 01.docx).

Please let me know if I do anything wrong.

Best Regards

Herbert

Hi Herbert,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,

finally I managed to assemble a little sample solution which will show you what issues I’m facing.

Click on “Edit Template” Button to layout the template in Word. You’ll see that fieldname are truncation compared to the names in the data source.

Click on “Mail Merge” to create a new mail merge document. You’ll see that all fields with truncated field names are not filled.

I left out the Aspose.Words.dll just to save space.

Best regards

Herbert

Hi Herbert,

Thanks for sharing the detail. You are using MailMerge.CleanupOptions. This property is used to get or set a set of flags that specify what items should be removed during mail merge.

The mail merge fields at the right side of template document does not exists in Xml. Please execute the following code example to check this.

DataSet mmData = new DataSet();
mmData.ReadXml(MyDir + "Data.xml");
Console.WriteLine(mmData.Tables[0].Columns.Contains("OV_ElevatorESBNewYork_Contract_FeldZusa"));
Console.WriteLine(mmData.Tables[0].Columns.Contains("OV_ElevatorESBNewYork_SerialNo_FeldZusa"));
Console.WriteLine(mmData.Tables[0].Columns.Contains("OV_ElevatorESBNewYork_YearBuild_FeldZus"));
Console.WriteLine(mmData.Tables[0].Columns.Contains("OV_ElevatorESBNewYork_LastModification_"));

The MailMergeCleanupOptions.RemoveUnusedFields removes unused merge fields from the document. Please read following documentation links for your kind reference.
https://reference.aspose.com/words/net/aspose.words.mailmerging/mailmergecleanupoptions/
https://docs.aspose.com/words/net/clean-up-before-or-during-mail-merge/

Hi Tahir,

I think you didn’t got what I wanted.

Please use my sample and try to layout the template document with Word by clicking the “Edit template” button. You’ll see then, that Word truncates the fieldnames.

For this reason you cannot find the fieldnames in the datasource.

Please let me know how I can use longer fieldnames.

Best Regards

Herbert

Hi Tahir,

attached you’ll find a word template which I designed manually.

As you can see when you compare it to the former template the fieldnames are much longer (may hit +), matching the field names in the dummy csv file for layout and the data in xml.

Please let me know how this can be achieved by a normal end user which uses mail merge field wizard.

Best Regards

Herbert

Hi Herbert,

Thanks for your inquiry.

Please note that the mail merge field name in your document must match with the data source field’s name if you are using MailMerge.ExecuteWithRegions or MailMerge.Execute method. Please read about mail merge reporting engine from here:
https://docs.aspose.com/words/java/mail-merge-and-reporting/

Please read my reply here:
https://forum.aspose.com/t/41025

If you want the same output as generated by “Edit template” button, please use following code example.

Document doc = new Document("C:\\Temp\\Template Test 01.dotx");
doc.MailMergeSettings.Clear();
string query = "SELECT * FROM 'TempMMData'";
MailMergeSettings mms = doc.MailMergeSettings;
mms.MainDocumentType = MailMergeMainDocumentType.MailingLabels;
mms.DataType = MailMergeDataType.TextFile;
mms.DataSource = "C:\\Temp\\TempMMData.csv";
mms.Query = query;
mms.LinkToQuery = false;
mms.ViewMergedData = true;
doc.Save("C:\\Temp\\Out.docx");

MailMergeSettings Class specifies all of the mail merge information for a document.

You can use this object to specify a mail merge data source for a document and this information (along with the available data fields) will appear in Microsoft Word when the user opens this document. Or you can use this object to query mail merge settings that the user has specified in Microsoft Word for this document.

You do not normally need to create objects of this class directly because Mail merge settings of a document are always available via the MailMergeSettings property.

To detect whether this document is a mail merge main document, check the value of the MainDocumentType property.

To remove mail merge settings and data source information from a document you can use the Clear method. Aspose.Words will not write mail merge settings to a document if the MainDocumentType property is set to NotAMergeDocument or the DataType property is set to None.