Free Support Forum - aspose.com

Formatting a Merged Date in word

Hi - I think this is relatively simple but am probably complicating it! Basically I want to merge an aspose data field into Word and change its format - the date is held in our database as 10/01/2010 but I want it to merge as 10 January 2010. I think this quite easily doable in word rather than Aspose (I'm more of an end user than an Aspose programmer), and hve the switch ( /@ DD MMM YYYY) figured out, but I can't get Word to recoginse the merged Aspose field as a Word mrgefield. When I try to bookmark the Aspose merge field/ bookmark I get a null parameter error in our app. Any help at all would be really appreciated.
This message was posted using Aspose.Live 2 Forum

Hi

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

Thanks for your request. As I can see Aspose.Words recognizes date string perfectly. Here is code I used for testing. I also attached my input and output documents.

// Open template.

Document doc = new Document(@"Test001\in.doc");

// Execute mail merge.

doc.MailMerge.Execute(new string[] { "test" }, new object[] { "10/01/2010" });

// Save output document

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

I use the latest version of Aspsoe.Words for testing. You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards.

Hi,


We have a similar problem, I tried the docs attached and the date was not formatted in the output.
A customer wants the date formatted without the time
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>“04/10/2012
04:09”, so they just want “04/10/2012” to appear in merged document. dd.MM.yyyy
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>I’ve attached a sample source file. I hope you can help with this issue. We have release our product with Aspose 11.1 (words for java).
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>From reading other posts this should be formatted without any extra coding on our side?
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>I build the IMailMergeDataSource from our data and call the Doc.getMailMerge().execute(mergeDataSource);
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>Do I need to do extra for this to work or can the customer fix up the fields in their template?
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>Thanks,
<span lang=“EN-US” style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:SimSun;mso-fareast-theme-font:
minor-fareast;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>Eamonn
Hi Eamonn,

Thanks for your inquiry.

I tested your scenario with the latest version of Aspose.Words i.e. 13.3.0 and was unable to reproduce any issue on my side. So, I would suggest you please upgrade to Aspose.Words 13.3.0. You can download it from the following link:
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

You can also make use of FieldOptions.FieldUpdateCultureSource property to specify what culture to use to format the field result. Please note that by default, the culture of the current thread is used and this setting affects only date/time fields with \\@ format switch.

For example, the following code snippet shows how to specify where the culture used for date formatting during field update and mail merge is chosen from.

// Set the culture used during field update to the culture used by the field.

doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;

doc.MailMerge.Execute(new string[] { "quot_createddate" }, new object[] { new DateTime(2011, 1, 01) });


If we can help you with anything else, please feel free to ask.

Best regards,