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.
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();
}
privatevoid 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());
}
}
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.
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.