when combining excel data how to have it replicate the sheets organization as well

조회 수: 1 (최근 30일)
I followed this example that i found on here, i need multiple excel to be all combine in one but I have data on multiple sheets
how do i modify it to tranfer all sheets thank you
fileDir = 'C:\test folder';
outfile = 'C:\test folder\MASTER.xls';
addpath(fileDir);
fileNames = dir(fileDir);
fileNames = {fileNames.name};
fileNames = fileNames(cellfun(...
@(f)~isempty(strfind(f,'.xls')),fileNames));
for f = 1:numel(fileNames),
[~, ~, raw] = xlsread( fullfile(fileDir, fileNames{f}));
xlswrite(outfile, raw, fileNames{f});
end
  댓글 수: 4
Ihaveaquest
Ihaveaquest 2023년 1월 9일
sorry i am still lost.. I have data in a loop and want to write to the same excel file
dpb
dpb 2023년 1월 10일
Well, so are we without the supporting information/description of the actual form of the input and what it is you're really trying to accomplish.
If you don't want to change workbook file names, then don't create new filenames inside the loop; of course, then you need to know you're writing what you want to what workbook.
If the idea is to do something with multiple sheets in an input file, then as suggested earlier, use sheetnames to return the list of sheets by name in the workbook you opened and then iterate over that array of sheets with the 'Sheet',sheetname named parameter-value pair, reading each in turn and doing what it is that is wanted with each inside that loop. I also pointed out there is the 'Append' named parameter which is either True/False that lets you append new data onto the given sheet (True) rather than overwriting the entire sheet (False).
But, we're just guessing at what it is you're really trying to do and what the input data files really look like...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by