在C#中保存导出的Excel时引发异常 [英] Exception thrown on saving an exported excel in C#

查看:198
本文介绍了在C#中保存导出的Excel时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Windows服务中,我已使用Interop Excel将数据从数据库导出到excel.
当我尝试使用SaveAs或SaveCopyAs保存导出的excel时抛出异常.

异常显示:来自HRESULT的异常:0x800A03EC

我使用了以下代码:

Hi,

In my Windows service,I have exported the data from database into excel using Interop Excel.
An exception is thrown when i try to save the exported excel using SaveAs or SaveCopyAs.

The exception says: Exception from HRESULT: 0x800A03EC

I have used the following code:

string filename;
filename ="C://Test.test.xlsx";
excelWorkbook.SaveCopyAs(filename);




如果Windows服务中使用了COM对象,会有任何问题吗?


谢谢




Is there any issue if COM objects are used in Windows Service??


Thanks

推荐答案

请确保您具有对相应文件夹的写权限.
Make sure you have write permissions to the appropriate folder.


请确保您要覆盖的文件不是在excel(或任何其他应用程序)中打开.并且(Abhinav提到了)查看您的权限.并确保您在项目中引用了正确的Office版本(一个错误使我犯了同样的错误...)-仅当您安装了多个Office版本时.
Make sure the file you want to override is not opened in excel (or any other application). And (Abhinav mentioned it) have a look on your permissions. And make sure you reference the correct office version in your project (a mistake that gave me the same error...) - only if you have multiple office versions installed.


尝试这样:
string filename = Environment.CurrentDirectory + "\\test.xlsx";
excelWorkbook.SaveCopyAs(filename);


这篇关于在C#中保存导出的Excel时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆