Issues with excel object

Im getting a couple of errors....working with this excel object

Any Help would be much appreciated.

You can see a better looking example of the code here:
http://share.codelove.org/BlahBlah-2BdWFb9Q.html

The errors are:

error CS1501: No overload for method 'Open' takes '2' arguments
error CS1955: Non-invocable member 'Microsoft.Office.Interop.Excel._Workbook.Sheets' cannot be used like a method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;


namespace CSharpToMySQL
{
	public partial class frmMain : Form
	{
		private System.Data.Odbc.OdbcConnection OdbcCon;
		private System.Data.Odbc.OdbcCommand OdbcCom;
                private System.Data.Odbc.OdbcCommand OdbcComAlt;
		private System.Data.Odbc.OdbcDataReader OdbcDR;
                private Microsoft.Office.Interop.Excel.Workbook wb;
                private Microsoft.Office.Interop.Excel.Worksheet sh;
                private Microsoft.Office.Interop.Excel.Range rng;
		private string ConStr;
		private Form frmAbout;

		public frmMain()
		{
			InitializeComponent();
		}

                private void btnExcelValue_Click(object sender, EventArgs e)
        {

            if (OdbcCon.State == ConnectionState.Open)
            {
                wb = Microsoft.Office.Interop.Excel.Workbooks.Open(@"c:\test.xls",1);                      
                sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets(1);
                rng = sh.get_Range("A1","A1");
                rng.Value2.ToString();
                txtLog.AppendText("The Value is " + rng.Value2.ToString());
            }
        }



Your problems are lines 36 and 37.

error CS1501: No overload for method 'Open' takes '2' arguments

means that
wb = Microsoft.Office.Interop.Excel.Workbooks.Open(@"c:\test.xls",1);
Is wrong, try using Open(@"c:\test.xls"); without the ,1.

error CS1955: Non-invocable member 'Microsoft.Office.Interop.Excel._Workbook.Sheets' cannot be used like a method.


means that .Sheets is a variable, not a function.
sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets(1);
Try
sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets[1];

Although, It maybe [0] because it should start from 0. But who knows with Microsoft.
Thanks Zaita,

I got rid of 1 error with

sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets[1];

But the other one is lingering

I tried:

wb = Microsoft.Office.Interop.Excel.Workbooks.Open(@"c:\test.xls"); wb = Microsoft.Office.Interop.Excel.Workbooks.Open(@"c:\\test.xls");wb = Microsoft.Office.Interop.Excel.Workbooks.Open("c:\\test.xls");

all the same error as before I also tried some wierd stuff....

such as:

1
2
3
 // wb._Open(@"c:\test.xls",1);
           //wb = (Microsoft.Office.Interop.Excel.Workbooks)wb.Open += ("c://test.xls");
           //wb = Microsoft.Office.Interop.Excel.Workbooks 
.

which game me error code...

error CS0079: The event 'Microsoft.Office.Interop.Excel.WorkbookEvents_Event.Open' can only appear on the left hand side of += or -=


Last edited on
Did the Sheets error get solved?

You need to know the Open() function's proper argument list then. I don't use Visual C++ so I can't tell you. But Intellisense should tell you what it is.
Yea the sheets error seems to be good now, much thanks

Hey and i noticed that I list the class object as workbooks and then later... I use workbook...

Thats the way i have seen it in examples...

The intellisense does'nt list the correct options only 2.... Equal and ReferenceEqual

also heres the msdn pages..

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.open(VS.80).aspx

http://msdn.microsoft.com/en-us/library/bb179167.aspx

lastly could it be something declared wrong in the class or namespace ?
Last edited on
Topic archived. No new replies allowed.