Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
This is code :
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();
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
Posted
Updated 14-May-19 22:19pm
v2
Comments
Patrice T 15-May-19 3:09am    
What happen when you open the file directly in excel ?
Husky 23021988 15-May-19 3:14am    
Hi @Patrice, Open the file directly in excel is ok
Richard MacCutchan 15-May-19 3:09am    
The error message is clearly telling you that the system cannot read the file's content. You need to fix it in Excel first.
Husky 23021988 15-May-19 3:17am    
Hi @Richard MacCutchan, I was opened the file directly in excel, modify, save and close but when open by app is error still occurs
Richard MacCutchan 15-May-19 4:15am    
What is in the filepath string when you call the Open method?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900