473,800 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.___ComO bject" coming out of the string.

Any ideas C# gurus?

Only I cannot seem to get it right! Please help!
this.openFileDi alog1.FileName = "*.xls";
if (this.openFileD ialog1.ShowDial og() == DialogResult.OK )
{
InitializeCompo nent();
ExcelObj = new Excel.Applicati on();

Excel.Workbook xwSpreadsheet = ExcelObj.Workbo oks.Open("C:\\D ocuments
and Settings\\MTSUs er\\My Documents\\Visu al Studio Projects\
\WindowsApplica tion1\\bin\\Deb ug\\Countries.x ls",0,false,
5,"","",true,Ex cel.XlPlatform. xlWindows,"",tr ue,false,
0,false,true,fa lse);

Excel.Sheets sheets = xwSpreadsheet.W orksheets;
Excel.Worksheet worksheet = (Excel.Workshee t)sheets.get_It em(1);
for (int i = 1; i <= 10; i++)
{
////////NONE OF THESE ARE WORKING :(
//String y = (worksheet.Cell s[1,1]);
//Excel.Range range = worksheet.get_R ange("A"+i.ToSt ring(), "I" +
i.ToString());
//System.Array myvalues =
(System.Array)r ange.Cells.get_ Value(range);
//string[] strArray = //ConvertToString Array(myvalues) ;

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

}
}

May 21 '07 #1
1 12465
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.co m

<ao****@hotmail .comwrote in message
news:11******** **************@ x18g2000prd.goo glegroups.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.___ComO bject" coming out of the string.

Any ideas C# gurus?

Only I cannot seem to get it right! Please help!
this.openFileDi alog1.FileName = "*.xls";
if (this.openFileD ialog1.ShowDial og() == DialogResult.OK )
{
InitializeCompo nent();
ExcelObj = new Excel.Applicati on();

Excel.Workbook xwSpreadsheet = ExcelObj.Workbo oks.Open("C:\\D ocuments
and Settings\\MTSUs er\\My Documents\\Visu al Studio Projects\
\WindowsApplica tion1\\bin\\Deb ug\\Countries.x ls",0,false,
5,"","",true,Ex cel.XlPlatform. xlWindows,"",tr ue,false,
0,false,true,fa lse);

Excel.Sheets sheets = xwSpreadsheet.W orksheets;
Excel.Worksheet worksheet = (Excel.Workshee t)sheets.get_It em(1);
for (int i = 1; i <= 10; i++)
{
////////NONE OF THESE ARE WORKING :(
//String y = (worksheet.Cell s[1,1]);
//Excel.Range range = worksheet.get_R ange("A"+i.ToSt ring(), "I" +
i.ToString());
//System.Array myvalues =
(System.Array)r ange.Cells.get_ Value(range);
//string[] strArray = //ConvertToString Array(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
4704
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 the Microsoft based files with an OleDbDataAdapter. Then filling the contents of the first worksheet into a dataset. However when I try to add the XML based file to my dataset using an XmlTextReader I can never seem to get it to save to a...
4
6082
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 8.0;HDR=YES;IMEX=1;\""; OleDbConnection conn = new OleDbConnection(connection); try { DataSet ds = new DataSet(); conn.Open();
0
3674
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 worksheet first.. Unfortunately my code was throwing error like
12
6027
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 examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
1
22204
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 is: some cells in the excel sheet is having two lines value and four lines data, the text file is generating that value in a single line. (Ex. the cell value in address column is in four lines and should display in four lines in the text file...
6
2894
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 As Object 'workaround for excel 97
0
1864
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 of read data from excel, Invalid use of Null error came... In that current cell have an '#VALUE!" -> that means illegal value... I need to read same '#VALUE!"(exact cell value from excel)... #VALUE! -> means, formula error... But, i need to read...
3
6253
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5403
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.