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

Free Support Forum - aspose.com

worksheet.SheetToImage() throws NullReference exception?

Hello there,



I am currently evaluating aspose.cells for automating excel file reading and converting worksheets into images. I had a look at the documentation and it seemed like SheetToImage() was a good fit for that need,



however with the following code block, I get the Exception below.





Code:





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Aspose.Cells;



namespace ExcelExport

{

class Program

{

static void Main(string[] args)

{

var workbook = new Workbook();



//Open a designer file

string xlsFile = @“D:\Development.net\ExcelExport\RS232_Crossover_10094658_000.xls”;

workbook.Open(xlsFile);



//Set scroll bars

var sheet = workbook.Worksheets[0];



var sheetPicture = sheet.SheetToImage();

}

}

}





the ‘sheet’ variable is not null and actually contains all the data, but the following exception occurs on the sheet.SheetToImage(); line:



Object reference not set to an instance of an object.



at Aspose.Charts.SheetPrint.x658c13c9c9ee7e4d.x0314d23aa5c14a84(Int32 x3e0a106e44f5f6eb, Int32 xacf07c4ed65954c1, Int32 x6155c61fc47ceb1a, Int32 xa364300db00bde74, Int32 x433508a87b1e0cdf, Int32 x8e5bc30d03570f25)

at Aspose.Charts.SheetPrint.x658c13c9c9ee7e4d.x7af7e2c254ee5ace(Int32 x3e0a106e44f5f6eb, Int32 x6155c61fc47ceb1a, Int32 xa364300db00bde74, Int32 x433508a87b1e0cdf, Int32 x8e5bc30d03570f25)

at Aspose.Charts.SheetPrint.x658c13c9c9ee7e4d.x9e596c2fbcf44b1f(Int32 x3e0a106e44f5f6eb, Int32 x6155c61fc47ceb1a, Int32 xa364300db00bde74, Int32 x433508a87b1e0cdf, Int32 x8e5bc30d03570f25, Double x08db3aeabb253cb1, Double x1e218ceaee1bb583, Double xd3f2e0aa29e1f6c9)

at Aspose.Charts.SheetPrint.x658c13c9c9ee7e4d.xca4569f4511e9b8c(Int32 x69e9b567129e96cb)

at Aspose.Charts.SheetPrint.x658c13c9c9ee7e4d.x83e84e1d3bc59160(Boolean x6fb303b00fe33226, Int32 xc0c4c459c6ccbd00)

at Aspose.Cells.Worksheet.SheetToImage(Boolean isPaginate)

at Aspose.Cells.Worksheet.SheetToImage()

at ExcelExport.Program.Main(String[] args)

at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()







Am I missing something? Or has this something to do with the evaluation/trial version?

Hi,

Thanks for considering Aspose.

Could you post your template file here, we will check the conversion (Sheet2Image) and figure it out (if we found the problem) soon.

Thank you.

Hello there,



thank you for the quick response! Where should I send this to (email wise)?



Br,

-Jörg Battermann

Quick Update:



When I copy the affected Worksheet once to a new workbook, it actually does work perfectly fine:



static void Main(string[] args)

{

var workbook = new Workbook();

var workbook2 = new Workbook();



//Open a designer file

string xlsFile = @“D:\Development.net\ExcelExport\RS232_Crossover_10094658_000.xls”;

workbook.Open(xlsFile);



//Set scroll bars

var sheet = workbook.Worksheets[0];

workbook2.Worksheets.Clear();

workbook2.Worksheets.Add();

workbook2.Worksheets[0].Copy(sheet);



var sheetPicture = workbook2.Worksheets[0].SheetToImage();

sheetPicture.Save(@“D:\Development.net\ExcelExport\RS232_Crossover_10094658_000.png”, ImageFormat.Png);

}

}

Hi,

Thanks for providing us further info.

We will check your issue, we need your template file. You may post us your template file as an attachment here and mark as "Keep this post private" checkbox (when you reply to this post) , thus only you and Aspose staff can see and download your file. Alternatively, you may post the template file via my email: Click Contact button (attached to this message frame), in its dropdown list, click the option "Send Amjad Sahi an email" to send me the template file as an attachment.

Thank you.

Hi,

Thanks for sending us the template file.

Could you try the attached version (4.5.0.27), I tested it using the following code and it works fine:

Sample code:

Workbook workbook = new Workbook();
//Open a designer file
string xlsFile = @"f:\test\RS232_Crossover_10094658_000_copy.xls";
workbook.Open(xlsFile);
//Set scroll bars
Worksheet sheet = workbook.Worksheets[0];
Bitmap sheetPicture = sheet.SheetToImage();
sheetPicture.Save(@"f:\test\RS232_Crossover_10094658_000.png", ImageFormat.Png);

Thank you.

Amjad,



The function seems to work now! When will this be released as an official version (incl .Net 2.0 assemblies).



Oh and… are there .Net 3.5 assemblies of Aspose.Cells available, too?



Thanks!

-Joerg



Hi,

Well, we will release our next official release soon after completing some important tasks on hand. You may use this fix without any problem, it will work like an official release. This fix will work fine equally fine on any .net framework i.e.., 1.x, 2.0, 3.0 and 3.5. Normally, we provide two compiled binaries (.dlls): one of .net1.x and other for .net2.0 when we release our official release.

We will check if we can provide .net 3.5 compiled version for your need.

Thank you.

I have to correct myself, after trying it out a little more, I now get these exceptions:



“System.FormatException: Format specifier was invalid.”





at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)

at System.Double.ToString(String format)

at Aspose.Cells.ۥ.۬(String վ, Double ڳ)

at Aspose.Cells.ۥ.۪(String վ, Double ڳ)

at Aspose.Cells.ۥ.ۭ(Cell ெ, Style Ա, Object ೜, Boolean ೛)

at Aspose.Cells.Cell.get_StringValue()

at Aspose.Charts.SheetPrint.ዐ.ጊ(Int32 ጉ, Int32 ጋ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎)

at Aspose.Charts.SheetPrint.ዐ.ጎ(Int32 ጉ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎)

at Aspose.Charts.SheetPrint.ዐ.ገ(Int32 ጉ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎, Double Փ, Double Ք, Double ౕ)

at Aspose.Charts.SheetPrint.ዐ.ጆ(Int32 ጂ)

at Aspose.Charts.SheetPrint.ዐ.ዶ(Boolean ዷ, Int32 ۡ)

at Aspose.Cells.Worksheet.SheetToImage(Boolean isPaginate)

at Aspose.Cells.Worksheet.SheetToImage()

at Siemens.Med.CTE.PMP.Libraries.Utilities.Office.Excel.ToImage(String inputExcelFile, String configurationSheetName, String requirementTypeName, ImageFormat imageFormat, String outputDirectory, String fileNamePrefix)





TargetSite: {System.String FormatDouble(Double, System.String, System.Globalization.NumberFormatInfo)}

These strange characters actually -do- show up in the stacktrace… and they are not from the excel file etc or my code…



Any idea why this is happening?

Sent you the affected file.

Hi,

We received your template file.

Yes, we found the issue (you have mentioned) after an initial test, we will fix it soon.

Thank you.

Great! Thanks! Meanwhile I’ll go ahead and get clearance for the license purchase on monday :slight_smile:

Amijad,



any news on this particular problem?



Best regards,

-Jörg

Hi,

Please try this fix.

We have fixed this bug.

It seemed to have fixed that particular error, but now it stumbled upon yet ANOTHER one:





The left value must be less than the upper left column width:



at Aspose.Cells.Shape.set_Left(Int32 value)

at Aspose.Charts.SheetPrint.ዒ.ጌ(Int32 ጋ, Int32 ግ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎)

at Aspose.Charts.SheetPrint.ዒ.ጐ(Int32 ጋ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎)

at Aspose.Charts.SheetPrint.ዒ.ጊ(Int32 ጋ, Int32 ે, Int32 ૌ, Int32 ૉ, Int32 ૎, Double Փ, Double Ք, Double ౗)

at Aspose.Charts.SheetPrint.ዒ.ገ(Int32 ጄ)

at Aspose.Charts.SheetPrint.ዒ.ዸ(Boolean ዹ, Int32 ۡ)

at Aspose.Cells.Worksheet.SheetToImage(Boolean isPaginate)

at Aspose.Cells.Worksheet.SheetToImage()





… using Aspose.Cells(4.5.0.29).



Unfortunately I cannot provide this particular excel file since it contains highly confidential data. Does the stacktrace alone give enough information to track the issue down?

Removed the sensitive/confidential data and sent the file to Simon… hope that makes it a tad easier.



-J

Hi,

Could mail the file again? I did not get the attached file. Please mail to me and Amjad.

Thanks for your help. We will check it soon.

Did the file go through this time?

Hi,

Yes, we received your file and found the error you have mentioned. We will figure it out soon.

Thank you.