Is it possible to adjust page setup options in Excel with MATLAB?

8 ビュー (過去 30 日間)
Calabrese
Calabrese 2017 年 6 月 15 日
回答済み: Meng Li Gan 2019 年 2 月 1 日
If so, I would like to access Print, Page Setup, set to Landscape, and Fit to 1 pages wide and 100 pages tall. Then print to PDF with the same file name and delete the original *.xlsx file.

採用された回答

Jayaram Theegala
Jayaram Theegala 2017 年 6 月 19 日
You can use the "actxserver" command in MATLAB to create Excel COM object and then use the functions exported by the COM object to Print, Page Setup. To find more information about the Excel COM functions, click on the following URL:
For more information about "actxserver" command and an example script to see how to use Excel COM object with MATLAB, click on the following URL:
You might find the following MATLAB script helpful to get started:
e = actxserver('Excel.Application');
e.Visible = 1;
e.Workbooks.Open('<your path to Excel file>');
%Print out Sheet 1 with default printer and settings
e.Worksheets.Sheets('Sheet1').PrintOut
delete('<your path to Excel file>');
Also, if you just want to save the file as PDF, you can use the Workbook's "SaveAs" function. To find more information about this function, click on the following URL:
  1 件のコメント
Calabrese
Calabrese 2017 年 6 月 23 日
I am not familiar with actxserver functions. I was hoping it could be performed similarly to adjusting information within cells. Thank you for you answer nonetheless

サインインしてコメントする。

その他の回答 (1 件)

Meng Li Gan
Meng Li Gan 2019 年 2 月 1 日
I not sure is it the answer that you need but i just sharing here what I did for page setup.
excel = actxserver('Excel.Application');
excel.Visible = 1;
workbook = excel.Workbooks.Open('filename');
worksheet = workbook.Worksheets.Item(1); % Choose desired sheet
worksheet.PageSetup.Orientation = 2; %to set the page to landscape (if portrait change the 2 to 1)
% if want to customize the margin, you need to convert the inch to point (1 inch = 72 point
worksheet.PageSetup.LeftMargin = 12.96;
worksheet.PageSetup.RightMargin = 36;
worksheet.PageSetup.TopMargin = 36;
worksheet.PageSetup.BottomMargin = 36;
worksheet.PageSetup.HeaderMargin = 36;
worksheet.PageSetup.FooterMargin = 36;
worksheet.PageSetup.Zoom = false; %zoom must set to false, otherwise FitToPagesWide will be ingnored
worksheet.PageSetup.FitToPagesWide = 1;
worksheet.PageSetup.FitToPagesTall = 100;

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by