|
刚做完测试:
First, the Excel assembly must be added to the project. To do this you must add a reference to the Excel 10 Object Library (Excel XP) by going to the Project -> Add Reference menu item. Go to the COM tab of the dialog box that pops up and scroll down the Excel 10 Object Library. Double click on it and press OK. This adds the reference to your project. In the "using" section of your code, type
[PHP]
using Excel;
.....
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Application excelApp = new Excel.ApplicationClass();
excelApp.Visible = true;
Excel.Workbook newWorkbook = excelApp.Workbooks.Add (XlWBATemplate.xlWBATWorksheet);
string workbookPath = "d:/zy.xls";
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet2";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1" ;
MessageBox.Show(excelCell.Text.ToString());
}
[/PHP]
你直接把代码考过去就明白了
这里有一些英文文档,你看一下
http://www.codeproject.com/csharp/csharp_excel.asp |
|