필터 지우기
필터 지우기

How can write multiple Excel sheets into one excel file?

조회 수: 53 (최근 30일)
AHMET TALHA UZUMCU
AHMET TALHA UZUMCU 2020년 6월 26일
댓글: AHMET TALHA UZUMCU 2020년 6월 28일
Hi Everyone,
I am stuck with writing multiple Excel sheets into one Excel file. I have 31 sheets contained 1 Excel workbook and successfully imported them with " readtable" function with the help of for loop of of course.
However, when I try to add them horizontally and create a single workbook, it seems impossible. I have just wrote a simple function to do that task as follows:
function sheetss(filename,portion) % I Enter the file name as 'filename.xls' and the portion as 'A2:D1002' to extract only a part of the values.
sheets = sheetnames(filename);
T = cell(1,31); % preallocation
for i = 1:31
T{i} = readtable(filename,'Sheet', sheets{i},'Range',portion);
end
table(T{:}); % trying to extract all embedded tables in cell arrays
writetable(T,'Result.xlsx')

채택된 답변

meghannmarie
meghannmarie 2020년 6월 26일
I do not know if this is best way, but try this after your for loop:
C = cellfun(@table2cell,T,'UniformOutput',false); % Converts all the tables in the cells to cell arrays
C = [C{:}]; % Horizontally concatonates all the cell arrays into one cell array.
writecell(cells,'Result.xlsx'); %Writes cells to excel
  댓글 수: 1
AHMET TALHA UZUMCU
AHMET TALHA UZUMCU 2020년 6월 28일
Hi,
Thank you so much for this.
I am not sure this was the best way, but it certanly did what I want !

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

추가 답변 (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