المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : reading excel contents



C# Programming
04-09-2009, 02:02 PM
I tried using this code for reading excel data using c# :

bt the following part of the code is giving errors and is not being executed....

plz help !!!!


using System;
using System.Collections.Generic;
using System.Text;
using Excel;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Path = @"c:\gg.xls";
Excel.ApplicationClass app = new ApplicationClass();


Excel.Workbook workBook =
app.Workbooks.Open(Path,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0);


Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 0;

object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{
rowIndex = 2 + index;
string firstName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString();
string lastName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString();
Console.WriteLine("Name : {0},{1} ", firstName, lastName);
index++;
}
}
catch (Exception ex)
{
app.Quit();
Console.WriteLine(ex.Message);
}
}
}
}


the error is at "Excel.Workbook workBook = app.Workbooks.Open" :

Error 1

No overload for method 'Open' takes '15' arguments C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ConsoleApplication1_trytry\ConsoleApplication1_trytry\Program.cs 16 39 ConsoleApplication1_trytry