protected bool IsExistExecl()
        {
            try
            {
                xlApp = new Excel.Application();
                if (xlApp == null)
                {
                    returnMessage = "无法创建Excel对象,可能您的计算机未安装Excel!";
                    return false;
                }
            }
            catch (Exception ex)
            {
                returnMessage = "请正确安装Excel!";
                //throw ex;
                return false;
            }            return true;
        }

解决方案 »

  1.   

    在这个地方出现错误 xlApp = new Excel.Application();
      

  2.   

    xlApp 
    光有赋值,声明呢
      

  3.   

    using Excel = Microsoft.Office.Interop.Excel;
      

  4.   

    Excel.Application xlApp = new Excel.Application(); 
    当然应该是这样用,xlApp要赋值成Excel.Application的实例,它自己必须是个Excel.Application类型的对象
    你不能先把他声明成COM对象啊
      

  5.   

            private Excel.Application xlApp;
      

  6.   

    什么就using
    好好查查using的用法,不能乱用啊
      

  7.   

    using用法
    要么写在类外面,最前面
    using system.IO;要么写成
    using()
    {
    }
    的形式
      

  8.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Excel = Microsoft.Office.Interop.Excel;
    using System.Data;
    using System.Drawing;
    using System.Collections;
    using System.Diagnostics;
    using System.Data.OleDb;
    using System.Windows.Forms;namespace QRCode
    {
        public class ExcelIO : IDisposable
        {
            #region Constructors
            private ExcelIO()
            {
                status = IsExistExecl() ? 0 : -1;
            }        public static ExcelIO GetInstance()
            {
                //if(instance == null)
                //{
                //    lock (syncRoot)
                //    {
                //         if(instance == null)
                //         {
                //            instance = new ExcelIO();
                //         }
                //    }
                //}
                //return instance;
                return new ExcelIO();
            }
            #endregion        #region Fields
            private static ExcelIO instance;
            private static readonly object syncRoot = new object();
            private string returnMessage;
            private Excel.Application xlApp;
            private Excel.Workbooks workbooks = null;
            private Excel.Workbook workbook = null;
            private Excel.Worksheet worksheet = null;
            private Excel.Range range = null;
            private int status = -1;
            private bool disposed = false;//是否已经释放资源的标记
            #endregion        #region Properties
            /// <summary>
            /// 返回信息
            /// </summary>
            public string ReturnMessage
            {
                get { return returnMessage; }
            }        /// <summary>
            /// 状态:0-正常,-1-失败 1-成功
            /// </summary>
            public int Status
            {
                get { return status; }
            }
            #endregion        #region Methods
            /// <summary>
            /// 判断是否安装Excel
            /// </summary>
            /// <returns></returns>
            protected bool IsExistExecl()
            {
                try
                {
                    xlApp = new Excel.Application();
                    if (xlApp == null)
                    {
                        returnMessage = "无法创建Excel对象,可能您的计算机未安装Excel!";
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    returnMessage = "请正确安装Excel!";
                    //throw ex;
                    return false;
                }            return true;
            }
      

  9.   

    using Excel = Microsoft.Office.Interop.Excel;
    没见过这种写法,不报错?
    改成
    using Microsoft.Office.Interop.Excel;
      

  10.   

    COM错误:无法加载dll
    如果确认已安装了excel,看看它的版本和你在自己机器上引用的Excel组件版本一致
    其实你可以在catch块里多一道动态创建的操作
    try
                {
                    xlApp = new Excel.Application();
                    if (xlApp == null)
                    {
                        returnMessage = "无法创建Excel对象,可能您的计算机未安装Excel!";
                        return false;
                    }
                } 
                catch
                {
                          try
                          {
                                    var typeCLSID = Guid.Parse("000208D5-0000-0000-C000-000000000046");
                                    type = System.Type.GetTypeFromCLSID(typeCLSID);
                                    object excelComObj = Activator.CreateInstance(type); 
                          }
                          catch (Exception ex)
                           {
                                 returnMessage = "请正确安装Excel!";
                                 //throw ex;
                                  return false;
                            }
                }
    只给你思路,上面的GUID和progID可以通过 控制面板 > 管理工具 > 组件服务 -> DCOM 中找到(找不到则说明没有安装成功)
    object excelComObj = Activator.CreateInstance(type); 
    //或者你也可以通过ProID,也就是COM组件名的方式创建
    object excelComObj = Marshal.GetActiveObject("Microsoft Excel Application");  //VB中也可以用GetObject()
    object也可以用Net4.0之后的动态类型
    否则你会由于C#编译时的类型检查,使用组件里的函数时非常麻烦(不停地反射),当然用VB.Net也会很方便
      

  11.   

    不看代码,先查环境
    先看看office安装时excel的.net编程支持支持是否安装,
    如果是精简版或者绿色版的office往往出问题;
    其次,查下程序引用的版本和本地的版本是否一致,
    不一致,重新添加引用。
      

  12.   

    装Office201  能行的通吗