Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Nov 17, 2023 8:28 am

Hello,

our client reported 4th merge issue...

They try to merge a template with a calculation and get System.InvalidOperationException: 'Cannot find any fonts in specified font sources.

I took some time to research and found that the issue was introduced with 8.8.0 and is also present in the latest Spire. Previous versions look fine. Here is my code:

Code: Select all
var data = new DataTable();
data.Columns.Add(new DataColumn("Investor_Fiscalyearend", typeof(DateTime)));
data.Columns.Add(new DataColumn("Investor_Name", typeof(string)));
data.Columns.Add(new DataColumn("Investor_Sum1", typeof(int)));
data.Columns.Add(new DataColumn("Investor_Sum2", typeof(int)));
data.Columns.Add(new DataColumn("Investor_Sum3", typeof(int)));
data.Columns.Add(new DataColumn("Investor_Referralfee", typeof(int)));

var r = data.Rows.Add();
r["Investor_Name"] = "IA1";
r["Investor_Fiscalyearend"] = DateTime.Now;
r["Investor_Referralfee"] = 25;
r["Investor_Sum1"] = 100;
r["Investor_Sum2"] = 200;
r["Investor_Sum3"] = 300;

foreach (DataRow dr in data.Rows)
{
    using (var document = new Doc.Document())
    {
        document.LoadFromFile(template);
        document.MailMerge.ClearFields = true;

        var resultFile = Path.GetTempFileName() + ".docx";

        document.MailMerge.Execute(dr);

        document.IsUpdateFields = true;

        document.ViewSetup.DocumentViewType = DocumentViewType.PrintLayout;
        document.SaveToFile(resultFile);

        Process.Start(resultFile);
    }
}


The 3 previous merge issues reported by our clients are:

https://www.e-iceblue.com/forum/date-format-is-ignored-after-merge-eu-regional-settings-t11359.html
https://www.e-iceblue.com/forum/missing-thousand-separators-after-merge-t11360.html
https://www.e-iceblue.com/forum/wrong-merge-result-t12604.html

You can find attached the template and a merged document before the issue (version 8.7.0)

profiler007
 
Posts: 73
Joined: Wed Nov 13, 2019 11:32 am

Fri Nov 17, 2023 10:06 am

Hello,

Thank you for your inquiry.

I created a console project with NetFrame4.7.2 and the latest version Spire.Office to test your file and code you in win 10, but I haven’t encountered the same problem as you.
Please kindly note that our product will read the corresponding font data from the font library installed in the system based on the font names used in Word documents, and then draw the content with fonts to a new Word page. At the same time, by default, the font data will be embedded in the document. Based on the error you are currently experiencing, it seems that the font used in the document is not installed on your server. I suggest two solutions to address this issue:
Solution1: Install the fonts used in the Word document on the server or copy a copy of the locally installed font library to the server.
Solution2: Instead of installing the font, place the font files in any folder on the server, and then use the document.SetCustomFontsFolders(fontFolder) method to read it.

The complete sample code is as follows:
Code: Select all
Document document = new Document();
document.LoadFromFile(input);
document.SetCustomFontsFolders(fontFolder);
document.SaveToFile(output, Spire.Doc.FileFormat.Doc);

In addition, for your other issues, I have urged our Dev team to speed up fixing. Once there are any updates about them, I’ll inform you in time.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Mon Nov 20, 2023 12:27 pm

Hello,

thanks for the quick reply! This works, thanks!

However, we found two more problems:

1. When some of the fields used in calculations is DbNull.Value the result is

Sum1 + 50 = Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


You can use the same template that I have already uploaded. You can also use the same code as before with the only difference:

Code: Select all
r["Investor_Sum1"] = DBNull.Value;


2. Once I updated Spire to 8.10.2 I got the following exception at runtime:

System.IO.FileLoadException: 'Could not load file or assembly 'Spire.Doc, Version=11.8.5.0, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)'

I tested with console app, .NET Framework 4.7.2, Windows 10 with latest updates, Office 2021.

Regards

profiler007
 
Posts: 73
Joined: Wed Nov 13, 2019 11:32 am

Tue Nov 21, 2023 9:26 am

Hi,

Thank you for your feedback.
I tested the word file and code you provided through the latest version of Spire.Office for .Net 8.10.2 and didn’t reproduce your two problems.
For your second issue, this issue may be caused by dependency conflict, I suggest that you remove all dlls related to our product from your project and re-add the corresponding dlls from the latest Spire.Office for .NET 8.10.2 through Nuget.
I have placed my project to our server, you can download it from the following link:
https://www.e-iceblue.com/downloads/demo/35617Demo.zip
If my project doesn't help you, please offer your complete project.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.Doc

cron