Excel-Export Read-only problem
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2021-5-9
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.
采纳的回答
Aleksei Kukin
2021-6-1
When you open the workbook use additional parameters.
Try change "params.ew.Open(filename)" by "params.ew.Open(filename, 0, false)"
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!