How to export a set of tables to Excel
조회 수: 27 (최근 30일)
이전 댓글 표시
Hi, would anyone please be able to assist with this.
I have written several lines of code that generate specific tables. I would like to export all of these tables (2 examples shown below) into one Excel spreadsheet.
For example these are the lines of code with their generated tables all in one script. How can I use the 'writetable' function for both of these tables?
댓글 수: 0
답변 (2개)
Mrutyunjaya Hiremath
2023년 8월 7일
% Create a cell array to hold your tables
tables = {table1, table2, table3}; % Replace with your actual tables
% Specify the filename for the Excel file
excelFilename = 'output.xlsx'; % Replace with your desired filename
% Write each table to a separate sheet in the Excel file
for i = 1:length(tables)
sheetName = sprintf('Sheet%d', i); % Change to your desired sheet names
writetable(tables{i}, excelFilename, 'Sheet', sheetName);
end
Star Strider
2023년 8월 7일
One option using writetable is to use the 'Sheet' name-value pair (the first entry in the documentation section on Spreadsheet Files Only). Use a for loop and wither the index number for the sheet designator or a separate string or cell array containing the desired sheet names if you want to use those instead, and index into them.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!