本帖最后由 xinxin1982 于 2010-04-29 17:02:46 编辑

解决方案 »

  1.   

    这个问题请看
    http://www.csharp360.com/bbs/viewthread.php?tid=142&extra=page%3D1
      

  2.   


                const string missing = Type.Missing;
                Microsoft.Office.Interop.Excel.Application myexcel;
                Microsoft.Office.Interop.Excel.Workbook mybook;
                Microsoft.Office.Interop.Excel.Worksheet mysheet;
     
                string strFile;
                if (this.myexcel != null)
                {
                    myexcel = null;
                }
                //实例化myexcel对象
                myexcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
                //打开目标文件outputFile
                mybook = myexcel.Workbooks.Open(strFile, missing, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing);
                //设置第一个工作溥
                mysheet = (Microsoft.Office.Interop.Excel.Worksheet)mybook.Sheets.get_Item(1);
                //激活当前工作溥
                mysheet.Activate();
                //你的操作
                //保存目标文件
                mybook.Save();
                //释放对象
                mysheet = null;
                mybook = null;
                myexcel = null;
      

  3.   

    推荐 你用c# 4.0  COM的互操作性也被提高了。以后不用再写如下丑陋的代码:
    C# code
    var excelApp = new Excel.Application();
    // . . .
    excelApp.get_Range("A1", "B4").AutoFormat(
        Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3,
        Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing); 现在只需这么写就搞定了:
    C# code
      excelApp.Range["A1", "B3"].AutoFormat(
        Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2); 顺带一句,这段代码用到了另一个叫做“索引属性”的新特性,更多关于这个特性的信息可以参考http://msdn.microsoft.com/en-us/library/ee310208%28VS.100%29.aspx 这个特性只能用于COM互操作上,你不能创建自己的索引属性。
      

  4.   

    3楼的...谢谢...但是我前面就是把这些放到一个cs文件中实现的...
    觉得很不好...所以打算分成file,sheet,range等.cs..这样后怎么实现呢...4楼...谢谢...好容易才给大家换了win7...有了.net 3.5...又要弄4.0...还得等等把...
      

  5.   

    我的问题貌似还是没描述清楚...
    最刚开始.我如3楼所做...写在一个cs文件里面.然后编译成一个dll
    或者写成函数模式.如2楼所做..我现在是分成多个cs文件.比方说sheet.cs   range.cs   excel.cs..然后编译成一个dll..
    为了后期方便,打算分开.但是出现了1楼我说的问题...
    用excel 例子只是打个比方..貌似像zedgraph那样的整合dll依次来实现..
    myexcel.open(xxxxx);
    myexcel.worksheet.open(1);
    myexcel.range.read("A1");
      

  6.   

    现在我也不知道是什么回事,自己都不知道哪些组件怎么用,书上的带代码在Microsoft visual studio 2005中不能实现
      

  7.   

    用多态感觉比较好!
    这样就不需要直接知道定义的属性了!~
    只需要在类中return返回你所需要的属性