操作过Excel的大大来下吧 虽然知道希望渺茫

ChargeForward 2010-01-07 01:59:09
命名空间 using Microsoft.Office.Interop.Excel;
引用的是12.0.0.0版本DLL
代码如下


var missing = System.Reflection.Missing.Value;
Application excel = new Application(); //lauch excel application
if (excel == null)
{
//TODO:读不到这个Excel
}
else
{


excel.Visible = false;

excel.UserControl = true;

Workbook wb = excel.Application.Workbooks.Open(path, missing, true, missing, missing, missing,
missing, missing, missing, true, missing, missing, missing, missing, missing);

Worksheet ws = (Worksheet)wb.Worksheets.get_Item(1);
.....


同样是两台64为服务器 一台测试用 一台是正网

测试的时候没有任何问题 在正网服务器部署时发现没有安装Office 于是马上安装了Office2007
然后注册组件 修改COM组件访问权限为Everyone

然后运行时 Application excel = new Application(); 这句没有报错 也就是说可以实例化一个Excel对象

但是 Workbook wb = excel.Application.Workbooks.Open(path, missing, true, missing, missing, missing,
missing, missing, missing, true, missing, missing, missing, missing, missing);这一句会宕掉
抛出异常了


Server Error in '/' Application.
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))]
Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
Core.Store.NewImpStorage.ReadProdDataFromExcel(String path, Int32 shopId, Int32 startRowNum, String& errorTxt) in D:\Pro_SVN\trunk\Core\Store\NewImpStorage.cs:58
views.impproddata.updateexcel.Button1_Click(Object sender, EventArgs e) in D:\Pro_SVN\trunk\views\impproddata\updateexcel.aspx.cs:50
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082



本地的32位机不会报错 测试的那台是64位 也没有报错 就是正网这台 总出乱子 哎 愁死
...全文
578 47 打赏 收藏 转发到动态 举报
写回复
用AI写文章
47 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang3389r 2010-01-07
  • 打赏
  • 举报
回复
╮(╯▽╰)╭ 打嗝~!
shizhen_zhang 2010-01-07
  • 打赏
  • 举报
回复
UP
一直活在明天 2010-01-07
  • 打赏
  • 举报
回复
看看打开参数有没有错,2003和2007打开参数个数不同,但是在vba里好像没有多大区别,最好不用com组件,用vs dll自己带的。要是向叶面写excel就要看有权限没有,如果没有最好配置文件加个签名,但是这样可能会不安全。</httpHandlers>
<!--my authority of gi domain-->
<identity impersonate="true" userName="服务器用户名(gi域)\用户名" password="密码"/>
<httpModules>
yuanhuiqiao 2010-01-07
  • 打赏
  • 举报
回复
帮顶
hotmail_mk 2010-01-07
  • 打赏
  • 举报
回复
没用过控件的方法操作Excel,我以前用反射做过的,可以避开版本问题。你这个方法要注意编程用的excel控件和机器上安装的excel是不是一样的版本。
元宇宙之家 2010-01-07
  • 打赏
  • 举报
回复
加行代码试试:
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
Zerolzx 2010-01-07
  • 打赏
  • 举报
回复
呵呵,
特别 2010-01-07
  • 打赏
  • 举报
回复
帮顶
楼主如果着急的话,可以试试能不能采用ADO.NET来访问EXCEL
先跑起来再说
该错误可以慢慢解决
happyrain2010 2010-01-07
  • 打赏
  • 举报
回复
看抛出的异常是不是路径的问题啊 如果不是的话 可以重新装下office
itzrx 2010-01-07
  • 打赏
  • 举报
回复
附: 注册Excel组件命令: ~\Program Files\Microsoft Visual Studio 8\SDK\V2.0\Bin\tlbimp Excel.exe Excel.dll (前提是将Excel.dll拷到此目录)
itzrx 2010-01-07
  • 打赏
  • 举报
回复
管理工具 - 组件服务 -  DCOM配置 - Microsoft Excel 应用程序  - 安全 然后就看见三个权限配置了,点击编辑  给 newwork 用户增加 完全控制权限.
itzrx 2010-01-07
  • 打赏
  • 举报
回复
给Excel的COM组件的  启动和激活权限 + 访问权限 + 配置权限  这三个加上 NEWWORK用户,然后再全部配置成完成控制权限 。
wtnu200 2010-01-07
  • 打赏
  • 举报
回复
帮顶,接分
wangchao1982 2010-01-07
  • 打赏
  • 举报
回复
帮顶
风在指间 2010-01-07
  • 打赏
  • 举报
回复
不懂~~学习
cuike519 2010-01-07
  • 打赏
  • 举报
回复
建议你重新安装一下Excel,或者修复一下,可能是有冲突,这是个COM组件的内部错误。

或者使用regsvr32 C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE 重新注册COM组件。
RexZheng 2010-01-07
  • 打赏
  • 举报
回复


这应该是用户权限问题
三碗猪脚 2010-01-07
  • 打赏
  • 举报
回复
是不是权限问题,开放文件夹操作权限
wxhysoftsodc 2010-01-07
  • 打赏
  • 举报
回复
试试开源组件 ExcelDataReader呢?
jackson627 2010-01-07
  • 打赏
  • 举报
回复
命名空间 using Microsoft.Office.Interop.Excel;
引用的是12.0.0.0版本DLL




是不是你这个版本太低
加载更多回复(26)

110,536

社区成员

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

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

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