带有excel导出功能的程序,在客户机安装时出现的问题

jimever 2008-11-21 08:51:03
开发的环境是xp+office2003,用vs05自带的安装打包做了个安装程序,“系统必备”里加上了水晶报表、“从应用程序位置下载系统必备组件”。复制过去的有程序集:Microsoft.Office.Interop.Excel.dll、Microsoft.Vbe.Interop.dll、office.dll。

在客户机上安装后,excel导入功能可以用,但导出功能出错,说什么Excel.Range.set_Value不支持集合,具体提示:
************** 异常文本 **************
System.Runtime.InteropServices.COMException (0x80020011): 不支持集合。 (异常来自 HRESULT:0x80020011 (DISP_E_NOTACOLLECTION))
在 System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
在 Microsoft.Office.Interop.Excel.Range.set_Value(Object RangeValueDataType, Object )
在 myprj.ExcelUtil.DB2Excel(DataSet dataSet, String filename, Int32 sheetid)
在 myprj.GuideExportForm.button2_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
...全文
272 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimever 2008-11-23
  • 打赏
  • 举报
回复
wartim:
还是没搞定,你做成功过在excel2000和2003下都能运行的.net程序吗(给单元格赋值部分)
这里有几个问题:
首先excel2k和03下的写法就不同,03下是range.set_Value和range.Value2 方法;而在2k下是range.Value方法;网上常用的Sheet.Cell[0,0]=""这样的写法在03下根本通不过,有2k和03下都能通过的写法吗(给单元格赋值)
其次,那篇文章的意思是,改成excel2k的写法,再引用了My.Excel9.Interop.dll这个,就能在Excel2k和03下运行了?那我改成03的写法,再引用Excel03的dll,那能否在2k下运行?
yistudio 2008-11-22
  • 打赏
  • 举报
回复
用Range.Value替代一下
wartim 2008-11-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jimever 的回复:]
引用 3 楼 wartim 的回复:
http://www.devcity.net/PrintArticle.aspx?ArticleID=163

E文不好,看不大清楚,他是否说要在不同版本环境下都编译一次,或者在最低版本下编译的,高版本的都能用?
谁做过类似的事,帮帮忙
[/Quote]

那我翻译一下给你看

[System.Runtime.InteropServices.COMException] -2147352559 (80020011) Does not support a collection.
The above code produces this error when compiled on an Excel 2003 machine and run on Excel 2000
错误:不支持集合
发生的情况是在2003下编译的然后去低版本的装了2000的机子运行

Solution
解决方法
You will find three distinct methods suggested to work around these problems:
他说发现了3种方法
Build your project on different machines for compatibility with each respective version of Office.
第一种是在装有不同版本office的机子上都去重新编译下程序。
Install different versions of Office on your build machine (How-to).
第二种是是在你开发的自己上编译出不同版本office的程序(他给了你个链接告诉你怎么去做)。
Use "Late Binding" to call whatever version of Office is available at run-time
第三种是用“滞后生成”去相应不同版本的office(我也不知道他说的是什么方法)
Here, I suggest a fourth method: build to the lowest common denominator.
这里,他要推荐第四种方法:编译生成最大兼容性的程序,应该就死带常用方法的版本,不带各版本带的各自的特殊方法(大概这个意思。。。)。

Step-By-Step
一步步来。。。

1.Locate the Excel 9 (2000) Type Library
先找到excel 9(2000)的类型库
Normally, type libraries are named *.TLB
通常,类型库是以TLB为后缀名
After a little googling, however, I found that the Excel 9 type library is called EXCEL9.OLB
但在一点google后。。。。我发现了excel 9的类型库名字叫EXCEL9.OLB
I quickly found the EXCEL.OLB file on my (fully licensed and registered!!!) Office 2000 installation CD.
我很快地发现了EXCEL.OLB文件在我的(完全授权和注册过了的,意思就是正版!!!)Office 2000安装光盘里。

2.Copy the Excel 9 Type Library to the build machine
从光盘拷贝这个文件到你开发的机器的硬盘里
3.Create an Interop Assembly from the Excel9 Type Library
为这个Excel 9类型库文件创建一个托管程序(也就是*.Interop.dll)
Choose a unique name that will distinguish YOUR Interop DLL from others that may be found
选择一个唯一的名字去命名将要创建出来的*.Interop.dll,
Use the .NET SDK Tool called TLBIMP.exe to build your Interop Assembly from the command line
用vs bin目录下自带的TLBIMP.exe生成类型库的托管程序
他这里写了一个批处理文件,你照着他给的例子改,My.Excel9.Interop.dll就是上面说的那个你要命名的创建出来的托管程序的文件名,可以改掉

@echo off
SET prog="C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\TlbImp.exe"
%prog% EXCEL9.OLB /out=My.Excel9.Interop.dll
pause

4.Link this new Interop Assembly to the VS.NET project, and build
把生成的这个托管文件(My.Excel9.Interop.dll)连接进你的这个vs 工程里,而且编译生成。
他估计用的是vs2003,vs2005里不能在工程的添加引用里去浏览加入com,你要在工具箱里翻到com页,然后去找到刚生成的My.Excel9.Interop.dll
加进来,然后引用。

5.Update code to reference the new Interop Library
更改你的2003编译的程序里有关调用excel区间(Range)之类的一些写法为2000的写法(2003和2000参数个数和顺序可能不太一样)

6.Deploy this Interop Assembly in the \bin directory along with the project
Your project will now work on any machine with Office 2000 or higher

编译并发布,别忘了带上这个My.Excel9.Interop.dll一起发布
现在你的程序能在装有office2000或更高版本的机子上运行了。





jimever 2008-11-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wartim 的回复:]
http://www.devcity.net/PrintArticle.aspx?ArticleID=163
[/Quote]
E文不好,看不大清楚,他是否说要在不同版本环境下都编译一次,或者在最低版本下编译的,高版本的都能用?
谁做过类似的事,帮帮忙
jimever 2008-11-21
  • 打赏
  • 举报
回复
客户机是win2k+office2000
这有关系吗

vs05的发布安装能否支持多个win版本和office版本的?
shanying_0 2008-11-21
  • 打赏
  • 举报
回复
不是很明白。帮你顶把
啊兵 2008-11-21
  • 打赏
  • 举报
回复
查看一下用户的Office版本

或者重装一下用户的Office ,有一种病毒会导致Office功能出现异常。

110,566

社区成员

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

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

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