Aspose error :Input string was not in a correct format


#1

Hello,

I am using Aspose 8.2.2.0, and I have an error “Input string was not in a correct format” ,

I get this eception in two situations;


1- when I try to open a workbook:

Workbook workbook = new Workbook(FilePath);
Worksheet sheet = workbook.Worksheets[0];

after investigations, the “E-” is causing that problem, but , the same value in another workbook doesn’t causing the same problem !!! so Is there a special format to check or to avoid ??

bellow some examples of values :

Accepted values:

-2,51214798961441E-37

3,92523123377252E-39

not accepted values :
-5,46516808802406E-23

1,19335545904751E-22

3,92523123377252E-39



2-the second situation is when i copy a sheet to another :

Workbook _template = new Workbook(templateFilePath);

Worksheet _template_DecoSheet = _template.Worksheets[“Deco”];



Workbook _parentBook = new Workbook();

Worksheet _workSheetDeco = _parentBook.Worksheets[0];
_workSheetDeco.Copy(_template_DecoSheet); //Exception here

_workSheetDeco.Name = templateSheetDecomp1.Name;



So the question; how can I avoid this error; it’s very blocking for me, if the format of one cell is not correct, why to prevent to read all the sheet ?? could you help me please.


thanks in advance.

kcm


#2

Hi Kcm,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version: Aspose.Cells
for .NET v8.3.1.7
it works fine with both of your files. Let us know your feedback.


#3

Hello,

thank you for your quick reply !!

I have still the problem with the new version !!!

System.FormatException was caught
Message=Input string was not in a correct format
Source=mscorlib
StackTrace:
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s)
at Aspose.Cells.FormatCondition.?(String )
at Aspose.Cells.FormatCondition.(String )
at Aspose.Cells.FormatCondition.set_Formula1(String value)
at Aspose.Cells.FormatCondition.Copy(FormatCondition , CopyOptions )
at Aspose.Cells.FormatConditionCollection.Copy(FormatConditionCollection , CopyOptions )
at Aspose.Cells.ConditionalFormattingCollection.Copy(ConditionalFormattingCollection , CopyOptions )
at Aspose.Cells.Worksheet.Copy(Worksheet sourceSheet, CopyOptions copyOption)
at Aspose.Cells.Worksheet.Copy(Worksheet sourceSheet)
at ...CopySheetFromTemplate(Worksheet templateSheetDecomp1, Worksheet templateSheetDecomp2, Worksheet templateSheetDecomp3)

Thank you

kcm


#4

Hi Kcm,

Thanks for your posting and using Aspose.Cells.

I have looked into this issue further and was not able to replicate any issue with both of your files. I tested it with the current latest version 8.3.2.

I have attached the sample test project for your reference. Please download it and run at your end and see if it causes any exception or not.

Let us know your feedback.


#5

Hello,
Thank you for your reply, the project as you sent it worked
fine, but I when i tried it with another file , there is still this same
error.
Attached the same project with the file causing the exception.
Thank you by advance.

kcm


#6

Hi Kcm,

Thanks for your feedback and using Aspose.Cells.

I was not able to replicate this issue by running your sample project with your newly provided source Excel file. So this issue seems to be related to your machine. Please let us know your System Environment e.g OS 32/64 bit, .NET Framework etc.

Please also let us know which Regional Settings & Language Options you are using. On my machine, it is English - USA.


#7

Hello,

I don't understand this behaviour !!! if it works in your side, it should work on mine too !!!

Is there any configuration relative to regional and language settingss in Aspose ?

My machine is 64 bit, i am working with a french environnment !! is it the problem ??

please help, it's really impossible to use Aspose if this problem persists !!!!

Thank you for your help


#8

Hi Kcm,

Thanks for your feedback and using Aspose.Cells.

We were able to replicate this issue with the following sample code after setting the environment to French (France) using the latest version: Aspose.Cells for .NET 8.3.2.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43356 - Input string was not in a correct format error occurs when regional setting is set to French

C#

Workbook _template = new Workbook(“NewErrorCopyFile.xlsx”);

Worksheet _template_DecoSheet = _template.Worksheets[0];


Workbook _parentBook = new Workbook();

Worksheet _workSheetDeco = _parentBook.Worksheets[0];

_workSheetDeco.Copy(_template_DecoSheet); //Exception here


Exception:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
at System.Double.Parse(String s)
at Aspose.Cells.FormatCondition.„(String )
at Aspose.Cells.FormatCondition.(String )
at Aspose.Cells.FormatCondition.set_Formula1(String value)
at Aspose.Cells.FormatCondition.Copy(FormatCondition , CopyOptions )
at Aspose.Cells.FormatConditionCollection.Copy(FormatConditionCollection , CopyOptions )
at Aspose.Cells.ConditionalFormattingCollection.Copy(ConditionalFormattingCollection , CopyOptions )
at Aspose.Cells.Worksheet.Copy(Worksheet sourceSheet, CopyOptions copyOption)
at Aspose.Cells.Worksheet.Copy(Worksheet sourceSheet)
at AsposeProject.Program.f1() in F:\Shak-Data-RW\Projects\AsposeProject\AsposeProject\Program.cs:line 1963
at AsposeProject.Program.Main(String[] args) in F:\Shak-Data-RW\Projects\AsposeProject\AsposeProject\Program.cs:line 274
A first chance exception of type ‘System.FormatException’ occurred in AsposeProject.exe
An unhandled exception of type ‘System.FormatException’ occurred in AsposeProject.exe

Additional information: Input string was not in a correct format.


#9

Hello,

Ok so the problem is that !!!

Just a suggestion, i think the exception is throxn when he tries to parse double, there is a difference between english and french doubles separators ( coma or point)

System.Number.ParseDouble


#10

Hi Kcm,

Thanks for looking into this issue further and using Aspose.Cells.

We have added your comment in our database against this issue. Hopefully, it will be helpful for development team in fixing this issue. Please spare us some time. Once, there is some fix available for you, we will let you know asap.


#11

Hi,

Please try our latest version/fix: Aspose.Cells for .NET v8.3.2.2


We have fixed your issue “CELLSNET-43356” now.

Let us know your feedback.

Thank you.

#12

The issues you have found earlier (filed as CELLSNET-43356) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

#13
im using Aspose Cells for .NET version 8.8.1.0 and

my c# code is:
Workbook workbook = new Workbook();
workbook= new Workbook(@"C:\new.html");

im getting the same exception with my custom html file and the exception details are like:

threw an exception of type 'System.FormatException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233033
HelpLink: null
InnerException: null
Message: "Input string was not in a correct format."
Source: "mscorlib"
StackTrace: " at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\r\n at System.Convert.ToInt32(String value)\r\n at \u0003 .\u0002(Hashtable \u0002, String \u0003)\r\n at \u0005 .\u0002(String \u0002, ArrayList \u0003)\r\n at \u0003​ .\b()\r\n at \u0003​ .\u0002()\r\n at \u0005​ .\u0002(Stream \u0002)\r\n at \u0005​ .\u0002(String \u0002)\r\n at Aspose.Cells.Workbook.\u0002(String \u0002, LoadOptions \u0003)\r\n at Aspose.Cells.Workbook..ctor(String file)"
TargetSite: {Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)}

find the "new.html" file in the attachment

can anyone please help me on this ASAP?

#14

Hi Govardhan Yadav,


Thanks for the template file.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found an exception: “Input string was not in a correct format.” when loading an HTML file format. Also, your HTML file is a common HTML and does not seems to me an MS Excel oriented HTML file. We need to check if we could support such a file to be loaded via Aspose.Cells object model.
e.g
Sample code:

Workbook workbook = new Workbook();
workbook= new Workbook(@“C:\new.html”);

I have logged a ticket with an id “CELLSNET-44563” for your issue. We will look into it to figure it out (if possible) soon.

Thank you.

#15
Hi,

This is to inform you that we have fixed your issue (logged earlier as "CELLSNET-44563"). We will soon provide the fix after performing QA and incorporating other enhancements and fixes.

Thank you.

#16

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.8.3.8 and let us know your feedback.


#17

hi,


i tried with the latest fix of the tool u mentioned ,it is generating the output excel file.but the output excel file is empty.

this is my c# code used:
string myDir = @“C:”;
Workbook book = new Workbook(myDir+“new.html”);
book.Save(myDir + “output.xlsx”, SaveFormat.Xlsx);

is there anything i missed in my coding part?

please find the Html files i tested and output excel "output.xlsx"in attachments.

thank you in advance


#18

Hi,

Thanks for your feedback and using Aspose.Cells.

I have tested this issue with the following sample code using your source html with the latest version:
Aspose.Cells for .NET v8.8.3.8 and found, it is generating correct output excel file.

I have attached the output excel file and screenshot showing the output in Excel 2013 for your reference.

Please make sure, you are using the latest version. You can find the current running version via the CellsHelper.GetVersion() method.

C#
//Print your cells version
Console.WriteLine(CellsHelper.GetVersion());

string myDir = @“D:\Downloads\attachments”;
Workbook book = new Workbook(myDir + “new.html”);
book.Save(myDir + “output-shak.xlsx”, SaveFormat.Xlsx);

Console Output
8.8.3.8


#19

Hi,

Thanks for using Aspose.Cells.

We have looked into your issue further and found that while loading your test1.html and converting it into excel file, the results are not good.

We have therefore logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-44593 - Output excel file is not good while converting html to excel

I have attached the source html, its output excel file generated by Microsoft Excel and by Aspose.Cells for a reference.

C#
string myDir = @“D:\Downloads\attachments”;
Workbook book = new Workbook(myDir + “test1.html”);
book.Save(myDir + “output.xlsx”, SaveFormat.Xlsx);


#20

hi,


seen your output excel file, i think autofitting the columns is required,just check it out,i didnt gone through the whole tool properly,the features like “autofiting columns and also rows” and “wrapping the data” will helps a lot, if they already exist then its fine.

the issue can be cutted down some what with below lines of code,but i have other custom htmls “test2.html & test3.html & test4.html” which are not loading properly into Excel as Interop does.


Workbook book = new Workbook(txtHtmlPath.Text);
WorksheetCollection wsc=book.Worksheets;
foreach (Worksheet ws in wsc)
{
ws.AutoFitColumns();
}
string output = txtHtmlPath.Text.Replace(".html", string.Format(“Aspose{0}.xlsx”,DateTime.Now.ToString(“dd_MM_yyyy_hhmmss”)));
book.Save(output, SaveFormat.Xlsx);

here in “txtHtmlPath” we pass the html file path

find the html files and their output excel files in attachments “test234.zip”.

can you please help me on this?

thank you in advance