2011-04-27 1 views
1

안녕 나는 약 50-100 개의 텍스트 파일을 다른 스프레드 시트에 삽입하려고합니다. 모든 파일에는 두 개의 행 텍스트가 있으며, Thord 행은 숫자와 텍스트로 시작됩니다. 나머지는 1000 x 500 int입니다. 나는 이것을 matlab에서하고 싶다.MATLAB을 사용하여 100 개의 텍스트 파일을 하나의 엑셀 파일에 저장하지만 다른 스프레드 시트에 저장 하시겠습니까?

제발, 어떤 제안 ???

답변

1

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 
+0

당신은 조금 더 설명 될까요. 나는 더 많은 정보를 찾으려고 노력했지만 나는 할 수 없었다. – user531225

+0

위의 코드를 Windows 컴퓨터에서 실행되는 Matlab과 함께 사용해보십시오. Excel도 설치해야합니다. 이 코드는 Excel 프로세스를 시작하고 기존 워크 북 (설정해야하는 'filename'변수로 지정됨)을 열고 원하는 시트 이름, 행 및 열 및 값을 가진 cell_update()를 호출하여 특정 시트의 특정 셀에 쓰기 시작합니다. 셀에 넣어. – nimrodm

+0

Thx. 정의되지 않은 명령/기능 'cell_update'라는 오류 메시지가 나타납니다. – user531225

관련 문제