开发者

Using matlab to save a 100 text files to a one excel file but into different spread sheet?

Hi I have a about 50 to 100 text file which i want to impot their data into à different spread sheet. All the files have two row text, Thord row bega开发者_开发百科n with numbers and text after it. The rest is like 1000 x 500 int. I want to do this in matlab.

Please, any suggestion????


If you are running MATALB under Windows, you can use COM automation to control Excel and create the necessary file.

Take a look at xlswrite in the Mathworks file exchange for an example.

The referenced code does not create a new Excel sheet, but can populate any existing sheet you create beforehand (in an existing workbook of course).

If filename is the file to open, the following code (based on xlswrite) may be helpful:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜