当前位置:编程学习 > C#/ASP.NET >>

open office 2007 with C#

Sorry I can't type chinese right now...

I want to open excel by C#, and the default procedure to open excel is 2003, even after I add reference COM.Miscrosoft Excel 12.0 Object Library, this.Application.Version still shows that I am using 11.0 to open.

So is there any method that I can open the excel file by 2007 in C#? 

by the way, I can't change the default type to open excel, I can't even install a ShuRuFa...

xie xie a~ --------------------编程问答--------------------
namespace ExcelEdit
{
    public class ExcelEdit
    {
        public string file_name;
        public Excel.Application app;
        public ExcelEdit()
        {
        }
        public ExcelEdit(string file)
        {
            file_name = file;
            app = new Excel.Application();
            Console.WriteLine(app.Application.Version);//here always 11.0, 
            app.Workbooks.Open(file_name, true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            app.Visible = true;
        }
}
}
--------------------编程问答-------------------- re a re~ --------------------编程问答-------------------- 方法应该在2007和2003上基本都是一样的,我觉得应该不是代码问题:
1.首先应该确保本地安装了excel2007。
2.在lz添加引用的时候,把Com组件中添加的引用去掉,改成引用.Net组件中的“Microsoft.Office.Interop.Excel”,版本要12.0.0.0的那一个(不要用11.0.0.0)。
--------------------编程问答-------------------- 另外如果只是打开excel的话,我记得apache出过一个模块叫POI的,可以操作office。

但是poi是java上的,有一位叫tonyqu的兄弟,把poi移植到了.Net上,模块名叫NPOI,目前好像仅仅支持操作excel,这个NPOI我试过打开excel2003的文档,非常方便而且效率明显比微软的接口要快,同时不用本地机器安装office,直接就可以打开。唯一不确认的就是NPOI是否支持excel2007版本,这个lz可以关注下。

希望能够帮到lz,呵呵。 --------------------编程问答-------------------- 你需要引入12.0版本的office相关的dll,那样就可以了 --------------------编程问答-------------------- thanks.
1. I am sure I have installed office 2007.
2. I can't find Microsoft.Office.Interop.Excel in my .Net option, but after I add reference Microsoft Excel 12.0, Microsoft.Office.Interop.Excel appears in my reference column...

As I said... Even I add Excel 12.0 reference, the C# still open excel with 2003.... --------------------编程问答-------------------- re #5 lou,

which dll exactly?

Thanks~
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,