Import a cell array in excel
Mostrar comentarios más antiguos
Each cell contain other elements:
and a single element can contain some value like a matrix or a date:
Now i want to put all this cell array (called EXCEL) in Excel...but it doesn't show me the data and the matrices...what I did:
% MATLAB Automation client example
% Open Excel, add workbook, change active worksheet,
% get/put array, save.
% First, open an Excel Server.
e = actxserver('Excel.Application');
% Insert a new workbook.
eWorkbook = e.Workbooks.Add;
e.Visible = 1;
% Make the first sheet active.
eSheets = e.ActiveWorkbook.Sheets;
eSheet1 = eSheets.get('Item',1);
eSheet1.Activate;
% Put a MATLAB array into Excel.
for i=1:N
EXCEL{i}
eActivesheetRange = e.Activesheet.get('Range','A1:G7');
eActivesheetRange.Value =EXCEL{i};
end
% Get back a range.
% It will be a cell array, since the cell range
% can contain different types of data.
eRange = e.Activesheet.get('Range', 'A1:G7');
B = eRange.Value;
% Convert to a double matrix. The cell array must contain only
% scalars.
%B = reshape([B{:}], size(B));
% Now, save the workbook.
%eWorkbook.SaveAs('C:\Users\Folder\myfile.csv'); %or .xls
% Avoid saving the workbook and being prompted to do so
eWorkbook.Saved = 1;
eWorkbook.Close;
% Quit Excel and delete the server.
e.Quit;
e.delete;
It appears me:
even if matlab recognize that i passed [240x320] double and a Data but excel doesn't.
I would like obtain in excel like the first link in which i can click and see the sub element of each cell.
Regarding, Vincenzo
1 comentario
Walter Roberson
el 31 de Oct. de 2011
I do not recall ever hearing that Excel could support nested structures ? As far as I know, you can pass in a cell array but each element of the array has to be able to fit in to one Excel cell ?
Respuesta aceptada
Más respuestas (3)
Vincenzo
el 31 de Oct. de 2011
0 votos
Vincenzo
el 1 de Nov. de 2011
0 votos
1 comentario
Fangjun Jiang
el 1 de Nov. de 2011
Just write the first row,
eActivesheetRange = e.Activesheet.get('Range','A1:C1');
eActivesheetRange.Value={'Header1','Header2','Header3'};
Vincenzo
el 1 de Nov. de 2011
0 votos
Categorías
Más información sobre Use COM Objects in MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!