Laurence, can you help me to understand why the following code throws Aspose.Cells.ExcelException: Invalid formula in data validation settings. ? It seems that this code should work.
public void Decimal_2() { Excel excel = new Excel(); Cells cells = excel.Worksheets[0].Cells;
Hi Laruence. I tried the dll that you attached and I edited my code as you suggested. There is no longer an Aspose exception, but if I add double.MinValue or double.MaxValue to the worksheet, no numbers appear in the resulting file and the second column is very very wide.
cells[1, 1].PutValue(-1.23);
cells[2, 1].PutValue(1.23);
cells[3, 1].PutValue(int.MinValue);
cells[4, 1].PutValue(int.MaxValue);
cells[5, 1].PutValue(double.MinValue);
cells[6, 1].PutValue(double.MaxValue);
// C# decimals have smaller range than double, but greater precision:
Using the Aspose DLL that you most recently provided (version 3.8.1.5), I am seeing two problems. They are summarized in the attached text file that has C# code. When I run this code for Case /* A / I get a runtime exception. When I run it with Case / B */ I get the attached Excel document which has no numbers and a very wide second column.
For case A, it's a problem of .NET. It cannot convert back double.MaxValue and double.MinValue from string. Following code will throw this exception:
int min = double.Parse(double.MinValue.ToString());
For case B, it's caused by AutoFitColumn method. This method converts double.MaxValue and double.MinValue to a very long string which caused column B is too wide. I fixed it in the attached fix. Please try it.
ToString() only outputs up to 15 digits of precision, whereas internally double maintains 17. So the value is getting rounded, and the new value is outside of the acceptable range for a double. Try it with ToString(“G17”); that makes the exception go away.