Writing cell arrays to excel when each element contains a table
Afficher commentaires plus anciens
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
Réponses (1)
Kaitlyn Keil
le 7 Août 2018
0 votes
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 commentaires
Stephanie M
le 7 Août 2018
Kaitlyn Keil
le 7 Août 2018
Can you unpack the cell array to write the table directly in? So writetable(filename, A{x}), with whatever arguments are valid, essentially?
Stephanie M
le 7 Août 2018
Kaitlyn Keil
le 7 Août 2018
What is the final result you want for your data?
Stephanie M
le 7 Août 2018
Kaitlyn Keil
le 7 Août 2018
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!
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!