在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
首先在。net引用中引用“Microsoft.Office.Interop.Excel” using MSExcel=Microsoft.Office.Interop.Excel;
object missing = System.Reflection.Missing.Value; MSExcel.Application app = new MSExcel.ApplicationClass(); app.Application.Workbooks.Add(true); MSExcel.Workbook book = (MSExcel.Workbook)app.ActiveWorkbook; MSExcel.Worksheet sheet = (MSExcel.Worksheet)book.ActiveSheet; sheet.Cells[1, 1] = "源数据站点名称记录"; sheet.Cells[1, 2] = "匹配总数"; for (int k = 0; k < 2; k++) { sheet.Cells[k + 2, 1] = k; sheet.Cells[k + 2, 2] = k; } string n = Server.MapPath("link.xls"); book.SaveCopyAs(n); book.Close(false, missing, missing); app.Quit(); 如果出现: 无法嵌入互操作类型“Microsoft.Office.Interop.Excel.ApplicationClass”。请改用适用的接口解决办法是将引用的DLL:Microsoft.Office.Interop.Excel;的嵌入互操作类型改为false。 |
请发表评论