The ability to programmatically add the Header and Footer to an Excel worksheet can be implemented in MATLAB using the COM interface.
The ACTXSERVER command can be used to create a COM server running Microsoft Excel. You can then add the Header and Footer using the different methods for the workbook and then call XLSWRITE to write the data to the Excel worksheet as follows:
a = actxserver('Excel.Application');
a.Visible =1;
a.Workbooks.Add;
a.activeWorkbook.activesheet.PageSetup.LeftFooter = 'MyFooter';
a.activeWorkbook.activesheet.PageSetup.LeftHeader = 'MyHeader';
a.activeWorkbook.SaveAs('test.xlsx');
a.activeWorkbook.Close;
xlswrite('test.xlsx',[1 2 3]);
The following options can also be modified in a similar way:
a.activeWorkbook.activeWorksheet.PageSetup.CenterHeader
a.activeWorkbook.activeWorksheet.PageSetup.RightHeader
a.activeWorkbook.activeWorksheet.PageSetup.CenterFooter
a.activeWorkbook.activeWorksheet.PageSetup.RightFooter
Best Answer