如果你新建一个项目的话,首先要添加Microsoft.Office.Core 与Microsoft.Office.Interop.Exce这两个应用,然后就能很方便的操作了,示例代码(只实现了简单的读写):
1privateExcel._Application excelApp;
2privateWorkbook wbclass;
3
4excelApp = newExcel.Application();
5
6objectobjOpt = System.Reflection.Missing.Value;
7
8wbclass = (Workbook)excelApp.Workbooks.Open("E:\Book6.xlsx", objOpt, false, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt);
上面声明,引用,并把要操作的 excel 的路径传给他