Hi,
I am getting a runtime exception 'Input string was not in a correct format' when I am trying to read a cell of type 'Number' and when its blank in the excel sheet.
Below is the code while writing the excel. Here I m explicitly inserting __blank__ when the value is __zero__ and setting the datatype as XLCellValues.Number.
```
var locationValue = GetLocValue(1);
var cellindex = "A1";
worksheetProposal.Cell(cellindex)
.SetValue(locationValue == 0 ? string.Empty : locationValue.ToString())
.SetDataType(XLCellValues.Number);
```
Below is the code while reading the generated excel. Its throwing an exception when m tring the read the same cell "A1" when its blank.
```
var LocationId = worksheet.Cell("A1").Value; // Runtime exception 'Input string was not in a correct format' when its blank.
```
Does anyone came across such scenario? Any solution for this?
Comments: Thanks MDeLeon for ur reply. The exception issue is solved, but Arithmetic operations are not working when i try to reference those cells. In the generated execl, Cell A3 is supposed to be 300, but it is showing 0 in-spite there are values under A1 and A2. ``` var locationValue1 = 100; var cellindex = "A1"; worksheetProposal.Cell(cellindex) .SetValue(locationValue1 == 0 ? string.Empty : locationValue1.ToString()) .SetDataType(XLCellValues.Number); worksheetProposal.Cell(cellindex ).Style.NumberFormat.NumberFormatId = 2; var locationValue2 = 200; cellindex = "A2"; worksheetProposal.Cell(cellindex) .SetValue(locationValue2 == 0 ? string.Empty : locationValue2.ToString()) .SetDataType(XLCellValues.Number); worksheetProposal.Cell(cellindex ).Style.NumberFormat.NumberFormatId = 2; cellindex = "A3"; var formula = "SUM(A1:A2)"; worksheetProposal.Cell(cellindex ).SetFormulaA1(formula); ``` See the attachment for the excel sheet.
I am getting a runtime exception 'Input string was not in a correct format' when I am trying to read a cell of type 'Number' and when its blank in the excel sheet.
Below is the code while writing the excel. Here I m explicitly inserting __blank__ when the value is __zero__ and setting the datatype as XLCellValues.Number.
```
var locationValue = GetLocValue(1);
var cellindex = "A1";
worksheetProposal.Cell(cellindex)
.SetValue(locationValue == 0 ? string.Empty : locationValue.ToString())
.SetDataType(XLCellValues.Number);
```
Below is the code while reading the generated excel. Its throwing an exception when m tring the read the same cell "A1" when its blank.
```
var LocationId = worksheet.Cell("A1").Value; // Runtime exception 'Input string was not in a correct format' when its blank.
```
Does anyone came across such scenario? Any solution for this?
Comments: Thanks MDeLeon for ur reply. The exception issue is solved, but Arithmetic operations are not working when i try to reference those cells. In the generated execl, Cell A3 is supposed to be 300, but it is showing 0 in-spite there are values under A1 and A2. ``` var locationValue1 = 100; var cellindex = "A1"; worksheetProposal.Cell(cellindex) .SetValue(locationValue1 == 0 ? string.Empty : locationValue1.ToString()) .SetDataType(XLCellValues.Number); worksheetProposal.Cell(cellindex ).Style.NumberFormat.NumberFormatId = 2; var locationValue2 = 200; cellindex = "A2"; worksheetProposal.Cell(cellindex) .SetValue(locationValue2 == 0 ? string.Empty : locationValue2.ToString()) .SetDataType(XLCellValues.Number); worksheetProposal.Cell(cellindex ).Style.NumberFormat.NumberFormatId = 2; cellindex = "A3"; var formula = "SUM(A1:A2)"; worksheetProposal.Cell(cellindex ).SetFormulaA1(formula); ``` See the attachment for the excel sheet.