Writing cell arrays to excel when each element contains a table

4 visualizaciones (últimos 30 días)
Stephanie M
Stephanie M el 7 de Ag. de 2018
Comentada: Kaitlyn Keil el 7 de Ag. de 2018
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

Respuestas (1)

Kaitlyn Keil
Kaitlyn Keil el 7 de Ag. de 2018
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 comentarios
Stephanie M
Stephanie M el 7 de Ag. de 2018
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 el 7 de Ag. de 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!

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by