Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to read first cell from 2nd row Jerry N[_2_] Excel Programming 0 July 31st 07 12:36 AM
CAN YOU SET GRAPH TO READ, FORMULA IN A CELL AS A BLANK CELL AJ-foster Excel Discussion (Misc queries) 2 July 15th 06 08:34 AM
Read Undo list in Excel 2003 using Csharp code Rana Saha Excel Programming 0 June 1st 06 06:59 PM
A Macro to replace a string in a cell with a string from another cell??? Plica05 Excel Programming 2 August 16th 05 09:23 AM
Why am I unable to link a cell in one worksheet to a cell in anot. Dave Excel Discussion (Misc queries) 1 January 8th 05 01:51 AM


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"