How can I add a Header or a Footer to an EXCEL worksheet using MATLAB 7.7 (R2008b)?

4 vues (au cours des 30 derniers jours)
I am writing results to an EXCEL file using the XLSWRITE command. I currently have to manually add an EXCEL header/footer using View - > Header/Footer pull down menu items for each data worksheet. Using MATLAB, I am unable to programmatically write a Header/Footer for the worksheet I create.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Juin 2009
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

Plus de réponses (0)

Produits


Version

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by