Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Unable to read cell value when cell contains a string using CSharp
I am using C# to read values from an Excel file using the following code.
object ovalue = ((Microsoft.Office.Interop.Excel.Range)myWorksheet .Cells[1, 1]).Value2; string value = ovalue == null ? "" : ovalue.ToString(); If the target cell contains an integer, I can retrieve the value without issue. If the cell contains a string, ovalue is null so the string cannot be read. I have experimented with deleting data from other cells in the spreadsheet and sometimes I am able to delete random cells which will then allow the strings to read properly. This suggests some kind of corruption causing the value to get returned as null. There is no indication of a problem in the Visual Studio debugger output. In one case, I recreated the entire spreadsheet and copied all the cells from the corrupted spreadsheet to the new one. This seemd to fix the problem. I run into this fairly frequently and would like any thoughts on what might be happening and how to avoid the issue. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
unable to read first cell from 2nd row | Excel Programming | |||
CAN YOU SET GRAPH TO READ, FORMULA IN A CELL AS A BLANK CELL | Excel Discussion (Misc queries) | |||
Read Undo list in Excel 2003 using Csharp code | Excel Programming | |||
A Macro to replace a string in a cell with a string from another cell??? | Excel Programming | |||
Why am I unable to link a cell in one worksheet to a cell in anot. | Excel Discussion (Misc queries) |