一.COM组件操作excel
1.添加引用
using Excel = Microsoft.Office.Interop.Excel;
2.读取excel内容,修改单元格,关闭excel服务
//1.Initail excel application Excel.Application excel = new Excel.Application(); Excel.Workbook wb = null; excel.Visible = false; excel.DisplayAlerts = false; //2.Open excel wb = excel.Workbooks.Open(@"D:\Project\寿险电销\寿险电销文档\500IB名单导入模板.xlsx"); //3. Read excel value and update Excel.Worksheet ws = wb.Worksheets[1] as Excel.Worksheet; ws.Cells[2, 3] = "张三"; ws.Cells[2, 1] = "王五"; //4.Save excel wb.Save(); //5.Closed excel excel.Quit(); Process[] procs = Process.GetProcessesByName("excel"); foreach (Process pro in procs) { pro.Kill(); } GC.Collect();