Hi lancerxe,
This is application is kind of test application which tells how to use Microsoft Excel 10.0 Object Library, by using this library, how to load/read the excel contents.
Note: Here, I have created test.xls file which will be copied to c:\ before run the application.
Application developed using sample console application under VC# projects.
Steps:
1. Include the following reference into the project :
Microsoft Excel 10.0 Object Library
Microsoft Office 10.0 Object Library
2. Include the name space i.e. using Excel.
3. Creating the ExcelApplicationClass,Work
Find the complete code below:
using System;
using Excel;
namespace TestExcel
{
/// <summary>
/// Summary description for ExcelApplication.
/// </summary>
class ExcelApplication
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string Path = @"c:\test.xls";
// initialize the Excel Application class
Excel.ApplicationClass app = new ApplicationClass();
// create the workbook object by opening the excel file.
Excel.Workbook workBook = app.Workbooks.Open(Path,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows
"\t",
false,
false,
0,
true,
1,
0);
// get the active worksheet using sheet name or active sheet
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.
int index = 0;
// This row,column index should be changed as per your need.
// i.e. which cell in the excel you are interesting to read.
object rowIndex = 2;
object colIndex1 = 1;
object colIndex2 = 2;
try
{
while ( ((Excel.Range)workSheet.Ce
{
rowIndex = 2+index;
string firstName = ((Excel.Range)workSheet.Ce
string lastName = ((Excel.Range)workSheet.Ce
Console.WriteLine("Name : {0},{1} ",firstName,lastName);
index++;
}
}
catch(Exception ex)
{
app.Quit();
Console.WriteLine(ex.Messa
}
}
}
}
I hope this is what you are looking for.
All the very best.
Thanks,
Alpesh Patel.
Main Topics
Browse All Topics





by: YurichPosted on 2005-12-29 at 14:51:06ID: 15574400
have you added a reference to your application? I mean "Microsoft Excell 9.0 (or 10.0) Object Library"?
regs,
yurich