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

Free Support Forum - aspose.com

MailMerge and Desingfonts

Hello Support
I am using Word 2010 and Aspose 13.1.
When I create a MailMerge Field in Word and let apply the Default Font, which
is Designfont for Body (ger. Designschriftart (Textkörper)), the during MailMerge, where I detect the Font by the DocumentBuilder, then I just get always “Times New Roman”
(see it during Debug and in the generated Output Document).
I have currently the Default-Design named “Larissa”, which has as Body Fontkind
‘Calibri’ (10 pnts).
When I instead select the Fieldtext and Format it explictly with “Calibri” (but not
choosen from Designfont Register, but from other Fonts, then Aspose MailMerge
works as expected (Calibri detected and in Output Document visible).
Question now: Ist this behaviour as expected, because we are not allowed to choose
(or better let apply per default) any Designfont (Body or Header)?
or is it a bug in Aspose?
Or do I have to do some Special initializing when openening the Template during Code,
or initializie the MailMerge with something Special?
Has anybody else found this behaviour? I have not found any entry in the Forum nor
any notice in the bug list since Version 13.1 to 13.7
(I have not tested, if 13.7 would work).
Thanks for any Help
best regards
Nathan Troxler
Code sample:
In the callback for the Mergfield, I do:
(…)
d_aDocBld.MoveToMergeField(e.FieldName);
Aspose.Words.Font fldFont = d_aDocBld.Font;
(… apply ‘fldFont’ on the Run object to be inserted…)

Hi Nathan,

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

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • .NET Framework version (or Java version )
  • Provide information about your specific culture, such as the name of the culture, language and country/region.
  • Please supply us with the code from your application that is causing the issue
  • Please supply us with the input document that is causing the issue
  • Please supply us with the output document showing the undesired behavior
  • Please supply us with the expected document showing the desired behavior (You can create this document using Microsoft Word).

Hello
I am using:
Windows 7, 64-bit, Service Pack 1
Microsoft Word from Office Professional Plus 2010, Version 14.0.6129.500 (32-bit)
Visual Studio with Soloution/Project targeting .NET 3.5.
Aspose Words 13.1
The Input Template File is: ‘AA-CalibriTextkoerper.docx’
The generated (wrong) Output is: ‘AA-CalibriTextkoerper-OutputWrong.docx’
The correct Output should look like this: ‘AA-CalibriTextkoerper-OutputAA-CalibriTextkoerper-OutputShouldBe.docx’
Explanation:
As we see in the wrong Output, the MergeField has Font ‘Times New Roman’. We expected ‘Calibri (Textkoerper)’, assigned from a Designfontkind.
(Which is actually on my Machine/Installation the Default MS Word uses; I guess by applying Normal-Dot).
In the Output we see also, the whole Rest of the Text (i.e. not the MergeField), is now formated as ‘Calibri’, but no more ‘Calibri (Textkoerper)’ as in the Input Template.
For your Information:
When I Format the MergeField with just ‘Calibri’, then the MergeField in the Output is formated as expected with ‘Calibri’.
So the Problem is not the Font per se (here: ‘Calibri’), but the usage of it as part of a Designfontkind specification (here as Textkoerper, not Header).
(I have only a german Version accessible, where those Fonts are listed as “Designschriftarten”. It is the first Register in the DropDown Box when choosing
a Font in Word. Actually in this Register, there are always 2 Fonts, one for “Textkoerper” (Body), one for “Überschrift” (Headers).
When reading in with my Code the Word Document Template, I do nothing Special regarding Fonts, and do not edit the Document by code in any way.
Code: I use Aspose MailMerge Callback Class/Method to do the Merge.
In this case, I do provide the Merge by myself (i.e. not just handling back the appropriate Text to variable ‘.e’).
With the Document Builder, I move to the MergeField begin, and read the Font.
Then I let a class representing the Merge-Text fill actually the Run-Objects a the current Position with the Font given by Parameter.
When I debug, I can see the Font of the Fontbuilder: In all other cases a see the expected font, but in the current Problem case (Font from Designschriftarten), I see
the unexpected ‘Times New Roman’.
Code: In the classic FieldMerge Back handler code, look for
if( wasHandledSimpe == false)
{
… then here the code for this case (Handling is done with D5MMObjStringList, as an Adress could be several Lines. The provided case has for simplicity just one line ‘MyAdressName’.
d_aDocBld.MoveToMergeField(e.FieldName);
Aspose.Words.Font fldFont = d_aDocBld.Font; // <— Problem: Is ‘TimesNewRoman’ instead of ‘Calibri (Texkoerper)’ or at least ‘Calibri’.
}
Code Files.zip:
DocPartsManager_3.cs: Implemenation of partial class. From here the process
start with ‘ProcessTemplateToSerialLetter(…)’.
Then 'OpenDoc(string sFNm) is called in DocPartsManager.cs.
Then the ‘D5MMFieldMergeHandler’ Object ‘fmh’ is set as Callback Handler.
Then the MailMerge is started with ‘docTpl.MailMerge.Execute(tab1)’, with
‘tab1’ beeing a DataTable Object.
Then the File ‘DocPartsMailMergeClasses.cs’ has the FieldMerge Handler Class.
Within the public void FieldMerging(FieldMerginArgs e), the code part
within the If-Statement ‘if( wasHandlesSimple == false)’ is executed, where
I try to detect the Font with DocumentBuilder.
PS:
‘AA-CalibriTextkoerper-SelectionScreenshots.docx’ Shows a sreenshot, when
selecting the font for the mailmerge field (Screenshot actually can not Show
the selected text as selected; but Shows the Selection in the DropDownBox).
Hope this Information helps you investigating the error.
Please let me know if you Need more Information.
Appendix
What in German is called “Design” (Designfont/Kind) seems to be what
in the engl. Version is called a “Theme” (a set of Color, font (Body, Heading) and effects)

Hi Nathan,

Thanks for sharing the detail. I have tested the scenario and have not found the shared issue while using latest version of Aspose.Words for .NET 13.7.0.

The information about fonts you would like to get is defined in MS Word themes. When font is specified via theme MS Word shows Theme’s name in round brackets (for example “Cambria (Headings)”). The latest version of Aspose.Words provides an ability to get themes information. However, it is not available in the version which you are using.

Please upgrade to the latest version of Aspose.Words from here:
https://releases.aspose.com/words/net

If you still face issue, please create a simple application (for example a Console Application Project) that helps us reproduce the same problem on our end.

Hello Tahir
We are just before a release of our product, and the reported error is NOT a no go.
So before I install and test the newest Version (instead of ust using 13.1 and live with the Problem/behaviour reported), I have some questions:
Does it break any code I am using, regarding Fonts? Normally the application does NOT read documents/Fonts, but only produces Text, using Arial Font, set on Run-Object.
The MailMerge Part is a minor one in our product, wheras document generation through code ist not.
I do nothing Special with Fonts in the code, and of course I hope I can use it just as is with Aspose Version 13.7!!??
I actually do NOT need the ‘theme’ Information, I just want to preserve the font of
the merge field! For me, it does not matter if the font is part of theme or not!
I do not care what the other parts of the’theme’ are.
With the new Version, will I be able to still use the same code in the MailMerge Callback Handler: just Move the Document Builder to the MergeField, and then read the Document-Builder ‘Font’ Member???.
Best regards
Nathan Troxler

This time I can reply to myself:
Just downloaded Version 13.7, installed, compiled without any changes necessary:
And yes, now it works (MailMerge Field is formated “Calibri”, Rest of text
remains “Calibri (Textkörper)”.
Good work for Version 13.7, congratulation!!!
Best regards
Nathan Troxler

Hi Nathan,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.