Excel-Export Read-only problem
조회 수: 9 (최근 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!