How to save tables to different sheets in one xlsx file?

93 ビュー (過去 30 日間)
Niya Bedzheva
Niya Bedzheva 2019 年 9 月 3 日
コメント済み: FM 2022 年 7 月 13 日
Hello everyone,
i have a for loop reading several files and doing some calculations for each of them. What i want to do is to save the results from every file in a seperate sheet on one excel file.
%% reading the files
files = dir('*.txt');
for i=1:N
data = textscan (fid, '%s %s %s %s %s %s %s %*s %*s %s %*s', 'headerLines', 2);
R1=table (Time, beta, Sh, K, 'VariableNames' , {'Time', 'beta', 'Sh', 'K'});
this is how i tried, but the it is filling the sheet only with the first file.
  1 件のコメント
Andy 2019 年 9 月 3 日
from the Matlab documentation "wrtitetable(T) writes table T to a comma delimited text file." As far as I am aware, this format doesn't support multiple sheets. I have used xlswrite when writing to Excel as you can define the sheet to be written to.



Nicolas B.
Nicolas B. 2019 年 9 月 3 日
Have you done a step-by-step execution of your code to be sure that there are multiple files read?
Looking at it like that, I would just remore the square brakets to the sheet name:
Personnally, I'm using writematrix() the same way on different tables without any problem.
  4 件のコメント
FM 2022 年 7 月 13 日
I should have known better than to try exporting the CSV and writing VBA to import multiple files into different sheets within a common workbook. What a nightmare. This is a much more elegant solution, by orders of magnitude.


その他の回答 (0 件)


Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by