Writing cell arrays to excel when each element contains a table

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

Answers (1)

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 Comments

I tried to use xlswrite, but it seems like that doesn't work if each element in the cell array is actually a table or other structure. It will only write if the content of the cell is one thing.
Can you unpack the cell array to write the table directly in? So writetable(filename, A{x}), with whatever arguments are valid, essentially?
Yeah, but I'm trying to avoid counting rows so I don't overwrite one table with another
What is the final result you want for your data?
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
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!

Sign in to comment.

Asked:

on 7 Aug 2018

Commented:

on 7 Aug 2018

Community Treasure Hunt

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

Start Hunting!