open office 2007 with C#

intersun2 2011-06-03 02:52:56
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~
...全文
69 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
intersun2 2011-06-07
  • 打赏
  • 举报
回复
re #5 lou,

which dll exactly?

Thanks~
intersun2 2011-06-07
  • 打赏
  • 举报
回复
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....
bdmh 2011-06-04
  • 打赏
  • 举报
回复
你需要引入12.0版本的office相关的dll,那样就可以了
Maa 2011-06-04
  • 打赏
  • 举报
回复
另外如果只是打开excel的话,我记得apache出过一个模块叫POI的,可以操作office。

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

希望能够帮到lz,呵呵。
Maa 2011-06-04
  • 打赏
  • 举报
回复
方法应该在2007和2003上基本都是一样的,我觉得应该不是代码问题:
1.首先应该确保本地安装了excel2007。
2.在lz添加引用的时候,把Com组件中添加的引用去掉,改成引用.Net组件中的“Microsoft.Office.Interop.Excel”,版本要12.0.0.0的那一个(不要用11.0.0.0)。
intersun2 2011-06-03
  • 打赏
  • 举报
回复
re a re~
intersun2 2011-06-03
  • 打赏
  • 举报
回复
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;
}
}
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧