From excel to PDF with option

조회 수: 10 (최근 30일)
enrico maggiolini
enrico maggiolini 2024년 10월 23일
댓글: enrico maggiolini 2024년 10월 23일
i have an excel file with some sheets.
I need to take a defined sheet and print to a PDF (landscape orientation) with A4 size.
I've tried a lot of solutions but have some problem, with actxserver:
excel=actxserver('Excel.Application');
workbook=excel.Workbooks.Open('Excel_file_name'); % pick the correct xlsx file
worksheet=workbook.Worksheets.Item(1); % Choose desired sheet
worksheet.PageSetup.Orientation = 2; %to set the page to landscape
% customize the margin, usefull but not mandatory
worksheet.PageSetup.LeftMargin = 15;
worksheet.PageSetup.RightMargin =10;
worksheet.PageSetup.PaperSize=9; % 9 should be tha A4, tried but useless
worksheet.PageSetup.Zoom = false; %zoom must set to false, otherwise FitToPagesWide will be ingnored
worksheet.PageSetup.FitToPagesWide = 1;
worksheet.PageSetup.PrintArea='A1:AK38'; % useful but not mandatory
% print trials
worksheet.ExportAsFixedFormat('xlTypePDF','PDF_file_name',[],[],'false'); % with this it came out not in A4 but bigger
worksheet.PrintOut % with this it ask me a confirmation of the name and directory and considering that is in a for cycle to 100 files it is not a good idea...
worksheet.PrintOut(1,1,1,false,excel.ActivePrinter,true,false,name) % it gave me an error because it try to save an prn format file
  댓글 수: 1
enrico maggiolini
enrico maggiolini 2024년 10월 23일
Solved! the problem was the Adobe printer, solved changing the default printer as Microsfot Print to PDF

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by