Writing cell arrays to excel when each element contains a table

3 次查看(过去 30 天)
Hello,
I need to extract a range of data with different data types for each column. I need to do this for roughly 3000 sheets.
I need to find a good way to store my data as I loop through the sheets, so I tried populating an element of a cell array with the exported range with each iteration. The problem is I don't know how I can write that data to excel.
The range will always have the same number of columns and the number of rows is variable.
Thanks!
Stephanie

回答(1 个)

Kaitlyn Keil
Kaitlyn Keil 2018-8-7
Hi Stephanie,
I think what you are wanting is either writetable or xlswrite, as described in the page Write Data to Excel Sheets. It looks like xlswrite can directly take your cell array and filename, and even write each piece to a new sheet if that's what you'd like to do.
Hope that helps!
  6 个评论
Stephanie M
Stephanie M 2018-8-7
I want a spreadsheet that has the same number of columns as the ranges I'm reading and all the data so it's all in one place
Kaitlyn Keil
Kaitlyn Keil 2018-8-7
Is there a reason that table2cell wouldn't work for the initial conversion? If so, then this is how I might do it (roughly):
cur_row = 1;
for i = 1:num_sheets
tab = <however you access your table data>;
temp_storage = table2cell(tab);
upper_corner = ['A' num2str(cur_row)];
status = xlswrite(filename, temp_storage, sheet, upper_corner);
cur_row = cur_row + length(temp_storage);
end
sheet would just be constant.
This doesn't prevent you from counting rows, but I'm not sure why you are trying to avoid that in this case. Sorry if this isn't what you were hoping for!

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by