Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Nov 26, 2019 11:53 pm

ToImage not working on ubuntu.
The code is simple , but result is strange.

Code: Select all
[HttpGet("excel")]
public ActionResult Excel()
{
    using (var workbook = new Workbook())
    {
        workbook.CustomFontFilePaths = new string[] { "msyh.ttf" };
        Worksheet sheet = workbook.Worksheets[0];
        sheet.Range["A1"].Text = "Hello,World!";
        var image = sheet.ToImage(1, 1, sheet.LastRow, sheet.LastColumn);
        using (var sheetms = new MemoryStream())
        {
            image.Save(sheetms, ImageFormat.Png);
            return File(sheetms.ToArray(), "image/png");
        }
    }
}

And this is the font file where i downloaded:
github.com/chenqing/ng-mini/blob/master/font/msyh.ttf
a.png
Image on windows
a.png (2.46 KiB) Viewed 2071 times

b.png
Image on Ubuntu
b.png (3.74 KiB) Viewed 2071 times

jimifish
 
Posts: 3
Joined: Tue Nov 26, 2019 11:36 pm

Wed Nov 27, 2019 7:19 am

Hi,

Thanks for your inquiry.
In fact the text "Hello,World!" use default font instead of the custom font "msyh.ttf" with your code. And if the default font is not installed in your computer, there might be the issue you mentioned. Please refer to following code to set the custom font in your case:
Code: Select all
                workbook.CustomFontFilePaths = new string[] { "msyh.ttf" };
                var result = workbook.GetCustomFontParsedResult();
                Worksheet sheet = workbook.Worksheets[0];

                sheet.Range["A1"].Text = "Hello,World!";
                //Set the custom font for the range
                sheet.Range["A1"].Style.Font.FontName = result["msyh.ttf"] as string;
                ......

I have generated correct image on ubuntu with the latest Spire.XLS Pack(Hotfix) Version:9.11.14.
If you still have the issue, please send a sample project for testing. You could upload it here or send to us(support@e-iceblue.com) via email.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Nov 27, 2019 12:07 pm

Thanks for your quickly reply.
I tried your code ,but still get the problem,the url is 123.57.175.83/test/excel
I send an email which contains server information and project.

jimifish
 
Posts: 3
Joined: Tue Nov 26, 2019 11:36 pm

Fri Nov 29, 2019 1:35 am

Hi,

Thanks for your information via email.
Glad to hear that .NET Core 2.1 solves the issue. Regarding the issue with .NET Core 3.0, I will do the testing ASAP and update you.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Nov 29, 2019 2:38 am

Im sorry
In .NET Core 2.1 environment , the font has no bold and wrong position problem...

jimifish
 
Posts: 3
Joined: Tue Nov 26, 2019 11:36 pm

Fri Nov 29, 2019 3:49 am

Hi,

Thanks for your detailed information from QQ.
We will look into the new issues and update you on QQ ASAP.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS