将数据导出到Excel并对其应用格式

我想用xlswrite导出1xm-Cellarray xlswrite 。 单元arrays由m单元组成,每个单元包含一个ixn-Cellarray ,其中i大部分是2,但也可以是3,4,5或6.下面是数据的一个例子:

 a=[{{{'a'},{'b'},{'c'},{'d'};{'a'},{'b'},{'c'},{'d'}}},{{{'a'},{'b'},{'c'},{'d'};{'a'},{'b'},{'c'},{'d'};{'a'},{'b'},{'c'},{'d'}}},{{{'a'},{'b'},{'c'},{'d'};{'a'},{'b'},{'c'},{'d'}}}] a = {2x4 cell} {3x4 cell} {2x4 cell} 

我希望所有的单元格都被写在下面,但我希望能够在Excel中看到哪些行属于一个单元格。 我的想法是在数组单元格和另一个像这样的空行之间

 exportTable=[]; for jj=1:numel(a) exportTable=[exportTable;a{jj};repmat({[]},1,18)]; end 

然后使用xlswrite导出xlswrite ,但是这在导出的表格中看起来相当丑陋,并且不容易阅读。
现在我正在寻找一种方法来获取每个单元格颜色相同的颜色,直接使用matlab中的导出function或使用Excel作为input相应行的向量。
我可以实现每个单元格使用结束索引

 rows=cumsum(cellfun(@(x) size(x,1),a)) rows = 2 5 7 

但是我不知道如何在基于rownumbers的Excel中着色行。
我的例子所需的输出如下所示:
示例输出

任何使用Matlab或Excel的帮助表示赞赏。

 rows = cumsum(cellfun(@(x) size(x,1),a)) %Create an Excel object. e = actxserver('Excel.Application'); %Add a workbook. eWorkbook = e.Workbooks.Add; e.Visible = 1; %Make the first sheet active. eSheets = e.ActiveWorkbook.Sheets; eSheet1 = eSheets.get('Item',1); eSheet1.Activate for i = 1:length(a) ai = table2array( cell2table( a{:,i} ) ); % sorry for this construction if mod(i,2) ai_color = 3; else ai_color = 4; end ai_range = ['A',num2str(rows(i)-size(ai,1)+1),':',char('A'-1+size(ai,2)),num2str(rows(i))]; % ... and this :) % Set the color of cells eSheet1.Range(ai_range).Interior.ColorIndex = ai_color; %Put MATLAB data into the worksheet. eActivesheetRange = get(e.Activesheet,'Range',ai_range); eActivesheetRange.Value = ai; end SaveAs(eWorkbook,'myfile.xlsx') %If the Excel program displays a dialog box about saving the file, select the appropriate response to continue. %If you saved the file, then close the workbook. eWorkbook.Saved = 1; Close(eWorkbook) %Quit the Excel program and delete the server object. Quit(e) delete(e) %Note: Make sure that you close workbook objects you create to prevent potential memory leaks.