Excel-Export Read-only problem
Afficher commentaires plus anciens
Hello,
my created excel file is read-only, how i can change it? Here is my code:
function params = create_log_file(params)
if isfolder(params.savepath_log)
savepath_log = params.savepath_log;
else
savepath_log = pwd;
end
filename = params.logf;
filename = [savepath_log '/' filename];
c = cell(6, 2);
c{1,1} = 'Block-Nr';
c{2,1} = 'Gravur';
c{3,1} = 'Foliendicke';
c{4,1} = 'Anzahl Blätter (SOLL)';
c{5,1} = 'Aktuelle Anzahl Blätter:';
c{6,1} = 'Durchschnittliche Zeit pro Blatt (s)';
c{1,2} = params.bnr;
c{2,2} = params.inputs.bandtype;
c{3,2} = params.ft;
c{4,2} = params.nst;
c{5,2} = num2str(params.ns);
c{6,2} = sprintf('%.2f', 0.00);
writecell(c, filename,'Range', 'A1:B6');
c1 = cell(1,7);
c1{1,1} = 'Blatt-Nr.';
c1{1,2} = 'Datum/Uhrzeit ';
c1{1,3} = 'Zeit pro Blatt (s)';
c1{1,4} = 'Linienbreite';
c1{1,5} = 'Original Bild (Link)';
c1{1,6} = 'Berechnungsergebnis Kantenerkennung (Link)';
c1{1,7} = 'Bild Positionierung (Link)';
writecell(c1, filename,'Range', 'A8:G8');
sp = ' ';
sp = [sp sp sp];
writecell({sp, sp, sp}, filename,'Range', 'E7:G7');
% - Create an Excel object.
params.ex = actxserver('excel.application');
% - workbook.
params.ew = params.ex.Workbooks;
% - open file
params.ef = params.ew.Open(filename);
% - get sheet
params.es = params.ef.Sheets.Item('Sheet1');
function params = reopen_log_file(params)
if isfolder(params.savepath_log)
savepath_log = params.savepath_log;
else
savepath_log = pwd;
end
filename = params.logf;
filename = [savepath_log '/' filename];
% - reopen the Excel object.
params.ex = actxserver('excel.application');
% - workbook.
params.ew = params.ex.Workbooks;
% - open file
params.ef = params.ew.Open(filename);
% - get sheet
params.es = params.ef.Sheets.Item('Sheet1');
3 commentaires
Walter Roberson
le 9 Mai 2021
If you are making it through both writecell() then your created file is not write-only. However, it might still be open in MATLAB at the time you try to access it inside of Excel.
Tommy Schumacher
le 9 Mai 2021
Walter Roberson
le 9 Mai 2021
Any time you invoke Excel directly using ActiveX, you run into the risk that a file you worked with earlier might still be open in MATLAB due to buffering for efficiency. There is not a lot you can do about it other than not using MS Windows.
However, since MATLAB knows about it own buffering, a potential workaround would be to copyfile() the file and work with the copied version in Excel.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!