Error while retrieving value from ASPOSE worksheet cells

Hello,


I am trying to add a datetime cell (A1) with a time cell(B1).The formula for the result cell is =A1+B1.
I have formatted all the cells(datetime cell with datetime format, time cell with time format and result cell with datetime format). But when i try to retrieve value from the result cell, i see that Aspose is throwing exceptions as follows:

wrksht.Cells[0, idx].DateTimeValue returns ‘wrksht.Cells[0, idx].DateTimeValue’ threw an exception of type ‘Aspose.Cells.CellsException’ System.DateTime {Aspose.Cells.CellsException}

wrksht.Cells[0, idx].Value returns"#VALUE!"

I have attached the worksheet generated by Aspose. Can you please let me know why Aspose is not supporting the addition of cells.

Thanks,
Divya


Hi,


Thanks for the template file.


I have tested your scenario using our latest version/fix: Aspose.Cells for .NET v8.1.2.4 / Aspose.Cells for Java v8.1.2.4 it works fine.

Please see the sample code below that gives correct Time value in B1 cell.
e.g
Sample code:

var workbook = new Workbook(“e:\test2\test.xls”);

string stVal = workbook.Worksheets[0].Cells[“B1”].StringValue;
string val = workbook.Worksheets[0].Cells[“B1”].Value.ToString();


Thank you.

Hi,


But what i really want to know is why Aspose is throwing exception when i try to retrieve value like
wrksht.Cells[0, idx].Value

Thanks,
Divya

Hi Divya,

Thanks for your posting and using Aspose.Cells.

Actually, the type of cell B1 is string, therefore it cannot be converted to date time value and it throws exception.

Please see the following code and its debug output.

C#


Workbook workbook = new Workbook(“test.xls”);


Worksheet worksheet = workbook.Worksheets[0];


Debug.WriteLine(worksheet.Cells[“A1”].Type);

Debug.WriteLine(worksheet.Cells[“B1”].Type);

Debug.WriteLine(worksheet.Cells[“C1”].Type);


Debug Output:
IsDateTime
IsString
IsDateTime
Hi,

Can you please tell me how to add the values from cell A1 and B1, where A1 is of DateTime type and B1 is of String type.

Thanks,
Divya

Hi Divya,

Thanks for using Aspose.Cells.

We have logged your original issue in our database for investigation. The time value in cell B2 of your Excel file is treated as string value and Cell.DateTimeValue throws exception.

We will investigate this issue and fix it. 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-42921 - Time value in cell B2 is treated as string value.

Hi Divya,

Thanks for using Aspose.Cells.

Which tool did you use to create this file (test.xls)? The value of Cell B2 is a string
value. If you format cell as General in MS Excel, it does not change .In fact if
it’s a time value, it should became a double value.

If you created this file
with Aspose.Cells, please post your code.