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

4 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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

更多回答(0 个)

产品


版本

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by