Windows에서 MATALB를 실행하는 경우 COM 자동화를 사용하여 Excel을 제어하고 필요한 파일을 만들 수 있습니다.
예를 들어 Mathworks 파일 교환에서 xlswrite을 살펴보십시오.
참조 된 코드는 새 Excel 시트를 만들지는 않지만 미리 작성한 기존 시트를 기존 워크 시트에 채울 수 있습니다. filename
가 열 수있는 파일 인 경우
(xlswrite 기준) 다음 코드는 유용 할 수 있습니다
Excel = actxserver('Excel.Application');
op = invoke(Excel.Workbooks, 'open', [pwd filesep filename]);
set(Excel, 'Visible', visible); % you may safely remove this
cell_update(sheetname, row, col, value)
function cell_update(sheetname, row, col, value)
% Make the specified sheet active.
try
Sheets = Excel.ActiveWorkBook.Sheets;
target_sheet = get(Sheets, 'Item', sheetname);
catch
% Error if the sheet doesn't exist. It would be nice to create it, but
% I'm too lazy.
% The alternative to try/catch is to call xlsfinfo to see if the sheet exists, but
% that's really slow.
error(['Sheet ' sheetname ' does not exist!']);
end;
invoke(target_sheet, 'Activate');
Activesheet = Excel.Activesheet;
cellnum = [num2col(col) num2str(row)];
ActivesheetRange = get(Activesheet,'Range', cellnum, cellnum);
set(ActivesheetRange, 'Value', value);
end
당신은 조금 더 설명 될까요. 나는 더 많은 정보를 찾으려고 노력했지만 나는 할 수 없었다. – user531225
위의 코드를 Windows 컴퓨터에서 실행되는 Matlab과 함께 사용해보십시오. Excel도 설치해야합니다. 이 코드는 Excel 프로세스를 시작하고 기존 워크 북 (설정해야하는 'filename'변수로 지정됨)을 열고 원하는 시트 이름, 행 및 열 및 값을 가진 cell_update()를 호출하여 특정 시트의 특정 셀에 쓰기 시작합니다. 셀에 넣어. – nimrodm
Thx. 정의되지 않은 명령/기능 'cell_update'라는 오류 메시지가 나타납니다. – user531225