473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

cant read a string value from an excel cell?

Hi,

Im having a reaaally hard time with something... Im trying to read a
cell of data into a String variable. It seems like such a simple task
too... Get the excel spreadsheet, get the workbook, get the sheet, get
the cell, get the cells data and store it into a string.

But it wont work! Im really frustrated. the best I got was
"System.___ComObject" coming out of the string.

Any ideas C# gurus?

Only I cannot seem to get it right! Please help!
this.openFileDialog1.FileName = "*.xls";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
InitializeComponent();
ExcelObj = new Excel.Application();

Excel.Workbook xwSpreadsheet = ExcelObj.Workbooks.Open("C:\\Documents
and Settings\\MTSUser\\My Documents\\Visual Studio Projects\
\WindowsApplication1\\bin\\Debug\\Countries.xls",0 ,false,
5,"","",true,Excel.XlPlatform.xlWindows,"",true,fa lse,
0,false,true,false);

Excel.Sheets sheets = xwSpreadsheet.Worksheets;
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
for (int i = 1; i <= 10; i++)
{
////////NONE OF THESE ARE WORKING :(
//String y = (worksheet.Cells[1,1]);
//Excel.Range range = worksheet.get_Range("A"+i.ToString(), "I" +
i.ToString());
//System.Array myvalues =
(System.Array)range.Cells.get_Value(range);
//string[] strArray = //ConvertToStringArray(myvalues);

//MessageBox.Show(strArray[1]);

}
}

May 21 '07 #1
1 12428
Well, you have to get the actual Range object that corresponds to the
cell (you should be able to call the Range property on the Worksheet to give
you the appropriate object, which you might have to cast to a Range object).
Once you have that, you can get the value using the Value property.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ao****@hotmail.comwrote in message
news:11**********************@x18g2000prd.googlegr oups.com...
Hi,

Im having a reaaally hard time with something... Im trying to read a
cell of data into a String variable. It seems like such a simple task
too... Get the excel spreadsheet, get the workbook, get the sheet, get
the cell, get the cells data and store it into a string.

But it wont work! Im really frustrated. the best I got was
"System.___ComObject" coming out of the string.

Any ideas C# gurus?

Only I cannot seem to get it right! Please help!
this.openFileDialog1.FileName = "*.xls";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
InitializeComponent();
ExcelObj = new Excel.Application();

Excel.Workbook xwSpreadsheet = ExcelObj.Workbooks.Open("C:\\Documents
and Settings\\MTSUser\\My Documents\\Visual Studio Projects\
\WindowsApplication1\\bin\\Debug\\Countries.xls",0 ,false,
5,"","",true,Excel.XlPlatform.xlWindows,"",true,fa lse,
0,false,true,false);

Excel.Sheets sheets = xwSpreadsheet.Worksheets;
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
for (int i = 1; i <= 10; i++)
{
////////NONE OF THESE ARE WORKING :(
//String y = (worksheet.Cells[1,1]);
//Excel.Range range = worksheet.get_Range("A"+i.ToString(), "I" +
i.ToString());
//System.Array myvalues =
(System.Array)range.Cells.get_Value(range);
//string[] strArray = //ConvertToStringArray(myvalues);

//MessageBox.Show(strArray[1]);

}
}

May 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
4
by: Hardy Wang | last post by:
Hi all, I have following code to read Excel content into a DataSet string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel...
0
by: vinidimple | last post by:
Hi i have a serious problem while i was working in Excel.I want to fetch columns from an excel worksheet and i need to compare it with an sql querry fields,so i tried to open an excle...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
1
by: ashok0866 | last post by:
I had created a macro to read data from an excel sheet and write the values to a text file. I had used "ActiveSheet.Range("GB" & k).Value" command to read the values from the excel. The issue...
6
by: jagguy | last post by:
Hi, i cant read in data from excel 97 using vb.net 2003. I get an exception error . all i want to do is read in values from excel initially. I want to just test it using msgbox. Dim XL...
0
by: suresh_punniyakkodi | last post by:
Hellow Friends, I have one doubt, please help me... In Excel, i have lot of rows and coloumns, i need to read all cell values with in rows and coloumn limit... At the time...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.