Microsoft.Office.Interop.Excel 为什么老是报错

来源:百度知道 编辑:UC知道 时间:2024/06/11 02:30:56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using Microsoft.Office.Interop.Excel;
using System.Reflection;
using Microsoft.Office.Core;

程序老是说命名空间"Microsoft Office"中不存在类型或命名空间名称"Interop" 那我该怎么正确添加Microsoft.Office.Interop.Excel;

添加COM引用,包括:Microsoft.Excel.x.0.Object.Library,Microsoft.Office.x.0.Object.Library

建议安装正版OFFICE,而且版本在11.0以上(Office2003以上),引用以上两个Com后,在项目引用栏发现多了Excel、Microsoft.Office.Core,VBIDE三个 Library.

参考中加入Interop.Excel

在代码中写法:
Excel.Application _x=new Excel.Application();

卸载重新安装