打开excel文件时已发生错误,通过C#修改和保存 [英] Occur error when open excel file already exists, modify and save by C#

查看:290
本文介绍了打开excel文件时已发生错误,通过C#修改和保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过c#创建应用程序是Lab Connects。用于打开excel文件已经存在,修改和保存。但它出现错误:

I create application by c# is "Lab Connects".It use to open excel file already exists, modify, and save. But it occur error :

System.Runtime.InteropServices.COMException (0x800A03EC): Excel cannot access 'Lab Connects'. The document may be read-only or encrypted. at 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)

这是代码:

Excel.Application excel = new Excel.Application();
Excel.Workbook workbook = excel.Workbooks.Open(filePath);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
// Modify content ....
workbook.Save();
workbook.Close();

注意:Excel文件有宏。希望每个人都有解决方案!



我尝试过:



- 我为用户设置了完全权限(管理员)

- 我是从.xls更新excel文件到.xlsx和.xlsm(Excel使用宏)

= >但一切都不起作用

Note : Excel file has Macro. Hope there's a solution from everyone !

What I have tried:

- I was set for user is full permission (Administrator)
- I was update excel file from .xls to .xlsx and .xlsm(Excel use Macro)
=> But all is not work

推荐答案

访问链接: Excel Interop:System.Runtime.InteropServices.COMException(0x800A03EC):Microsoft Office Excel无法访问该文件 [ ^ ]



也许可以帮助你。
visit link : Excel Interop : System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file[^]

maybe help u.


这篇关于打开excel文件时已发生错误,通过C#修改和保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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