Filter löschen
Filter löschen

How to solve file permission problem after using excel activeX functions?

4 Ansichten (letzte 30 Tage)
pietro
pietro am 1 Jun. 2014
Kommentiert: Geoff Hayes am 1 Jun. 2014
Hi all,
I have a script where I make some computations and I copy all the results in a excel file. Moreover I want to nicely format its cells in order to improve the file readability. To format them I use activeX functions but when I try to open the created file with excel right after the computations I get the following warning in excel:
Myfile.xslx is already open. Reopening will cause any changes you made to be discharged. Do you want to reopen Myfile.xlsx?
If I click on YES the cell will not be formatted as I did in Matlab, otherwise the cells will be formatted. How could I solve this problem?
Here my code:
Excel = actxserver('Excel.Application');
Excel.Workbooks.Open(OutXLS);
HeaderRange=Excel.Range('B3:BY3');
HeaderRange.Font.Bold='True';
HeaderRange.HorizontalAlignment=3;
DataRange=Excel.Range('E3:M169');
DataRange.NumberFormat='0.00';
DamageRange=Excel.Range('N3:P169');
DamageRange.NumberFormat='0.000E+00';
DamagePercRange=Excel.Range('Q3:BY169');
DamagePercRange.NumberFormat='0.00';
Thanks
Cheers
  3 Kommentare
pietro
pietro am 1 Jun. 2014
Hi added the following code, and it seems to work:
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
clear Excel;
I don't know if it is the best way to do it.
Geoff Hayes
Geoff Hayes am 1 Jun. 2014
I think it is. Since the code started the operation to create a new file and update its contents, then the code should perform the save and closing of the file.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by