Unprotect excel file from matlab

12 次查看(过去 30 天)
MatlabFan
MatlabFan 2013-4-16
Hi, I am using the ProtecStatus2 file from the File Exchange to open a protected excel file. It doesn't work.
Excel = actxserver('Excel.Application');
Excel.visible = 1;
Woorkbooks = get( Excel, 'Workbooks' );
invoke(Woorkbooks, 'open', [pwd 'Book1.xlsx']);
ProtecStatus2(Excel, 'DONOTBREAK');
Error using
Interface.Microsoft_Excel_15.0_Object_Library.Workbooks/invoke
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Sorry, we couldn't find C:\Users\Cedric\Desktop\Learning
GUIBook1.xlsx. Is it possible it was moved, renamed or deleted?
Help File: xlmain11.chm
Help Context ID: 0
Error in PassUnprotect (line 4)
invoke(Woorkbooks, 'open', [pwd 'Book1.xlsx']);
I also tried using the xlsprotect function from the File Exchange, But, it also doesn't work even after I use xlsread.
xlsprotect('Book1.xls','unprotect_file','DONOTBREAK');
[NUM,TXT,RAW]=xlsread('Book1.xls');
Error using
Interface.Microsoft_Excel_15.0_Object_Library.Workbooks/invoke
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Sorry, we couldn't find C:\Users\Cedric\Desktop\Learning
GUI\Book1.xls. Is it possible it was moved, renamed or deleted?
Help File: xlmain11.chm
Help Context ID: 0
Error in xlsxprotect (line 120)
Workbook =
invoke(Excel.Workbooks,'open',file,0,0,1,varargin{1});
Error in PassUnprotect (line 3)
xlsprotect('Book1.xls','unprotect_file','DONOTBREAK');
What is going on here?
It has been a month that I've tried to figure this out, and I am really depressed.
Please help me, I need anyone's help.
I am getting nuts about this.
  5 个评论
Ahmed A. Selman
Ahmed A. Selman 2013-4-18
What version of Windows (or any other OS) you're using? Perhaps removing the directory entirely to another (safer) place, say, D:\, might solve the issue. I think it's all about permission to change contents of some file in a Windows protected directory (\Users, in this case), and it's a common behavior of Windows 7.
Besides, you've used (book1.xls) and (Book1.xlsx) in the question above. I think you recognize that filename extension .xls is (excel 2003 down), and .xlsx is (excel 2007 up).
MatlabFan
MatlabFan 2013-4-18
Thans Ahmed, yes, I'm using Windows 7. Talking about permissions? I did not protect any directory, so I don't think that it is a permission to change problem. And yes, I do recognize that .xls is (excel 2003 down), and .xlsx is (excel 2007 up). But, I had changed all the xls. in the original xlsprotect code to xlsx., and only (so that you guys wouldn't raise this issue) when presenting to you my problem did I change all the xlsx. in the error message to xls., and obviously changed all of them but one. I did this because the version of excel on my computer is the 2013 edition. This xlsprotect function is just not working.

请先登录,再进行评论。

回答(1 个)

Friedrich
Friedrich 2013-4-17
编辑:Friedrich 2013-4-17
Hi,
the error you get:
Sorry, we couldn't find C:\Users\Cedric\Desktop\Learning
GUIBook1.xlsx
suggests a missing \ after GUI, doesnt it? Generating a path with [pwd 'Book1.xlsx'] is always a bad idea. Better is to use
fullfile(pwd,'Book1.xlsx')
When you did xlsread the path seems to be correct:
xlsread('Book1.xls');
Sorry, we couldn't find C:\Users\Cedric\Desktop\Learning
GUI\Book1.xls
However there is an x missing at the end, doesnt it? Book1.xlsX <=
  1 个评论
MatlabFan
MatlabFan 2013-4-17
I appreciate that you care to help,but No, I took care of it. I actually went into the code and changed all the xls to xlsx, and now so that you wouldn't get confused, I changed it back to xls when asking the question, except for the one you detected. Nevermind, when using a different computer that has the excel version format under xls, I still get the same problem.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by