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.

Thu Nov 05, 2020 7:09 am

Hi..
I'm using spire excel to convert a excel sheet to an image like below:
Code: Select all
Image img = sheet.ToImage(sheet.FirstRow, sheet.FirstColumn, sheet.LastRow, sheet.LastColumn);


and I get this error Error Image

However, when I change it to
Code: Select all
Image img = sheet.SaveToImage(sheet.FirstRow, sheet.FirstColumn, sheet.LastRow, sheet.LastColumn);

and the convert is successfull. So, May I know whats the different between "ToImage" and "SaveToImage", and which one should i use?

xiao0207
 
Posts: 43
Joined: Thu Dec 13, 2018 9:50 am

Thu Nov 05, 2020 9:59 am

Hello,

Thanks for your inquiry.
Kindly note that the method "SaveToImage(int firstRow, int firstColumn, int lastRow, int lastColumn)" is obsolete, you should use the method "ToImage(int firstRow, int firstColumn, int lastRow, int lastColumn)".
And I did an initial test with the latest Spire.Office Platinum(Hotfix) Version:5.10.0 but did not reproduce your issue. To help us investigate further, could you please provide us with your source Excel file? You can upload it here or send it to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Nov 06, 2020 4:56 am

Hi..rachel.lei
I encounter another problem when convert the file, So I also attached the file together for u to test.

Inside got 2 file:
Test File.xls: show Object reference not set to an instance of an object when convert.
Test File-convert image.xls: Unable to use ToImage function to convert

Thanks..
Attachments
sample.zip
(33.07 KiB) Downloaded 151 times

xiao0207
 
Posts: 43
Joined: Thu Dec 13, 2018 9:50 am

Fri Nov 06, 2020 7:23 am

Hello,

Thanks for your sharing.
I tested your two files and did reproduce your issue. I have logged them into our but tracking system with the following tickets. If there is any update, we will let you know. Sorry for the inconvenience caused.

- SPIREXLS-2917 : Test File-convert image.xls
- SPIREXLS-2918 : Test File.xls

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Nov 27, 2020 1:30 am

Hello,

Thanks for your patient waiting.
Glad to inform you that the issue SPIREXLS-2917 has been resolved in the newly released Spire.Office Platinum(Hotfix) Version:5.11.5. Welcome to download it and test.
As for the issue SPIREXLS-2918, actually it is because that there is an empty sheet in your file "Test File.xls". From Spire.XLS v10.11.2, our Spire.XLS have adjusted the image conversion function. For an empty sheet, the ToImage method will return null. So you need to determine whether the image object is null before saving the image, as shown below.
Code: Select all
            Workbook wb = new Workbook();
            wb.LoadFromFile("Test File.xls");
            foreach (Worksheet sheet in wb.Worksheets)
            {
                Image img = sheet.ToImage(sheet.FirstRow, sheet.FirstColumn, sheet.LastRow, sheet.LastColumn);
                if (img != null)
                {
                    img.Save(sheet.Name + ".png");
                }
            }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Dec 03, 2020 6:21 am

Hello,

Greetings from E-iceblue!
Has your issue been resolved? Thanks in advance for your feedback!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS