From excel to PDF with option

36 visualizzazioni (ultimi 30 giorni)
enrico maggiolini
enrico maggiolini il 23 Ott 2024
Commentato: enrico maggiolini il 23 Ott 2024 alle 12:03
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 Commento
enrico maggiolini
enrico maggiolini il 23 Ott 2024 alle 12:03
Solved! the problem was the Adobe printer, solved changing the default printer as Microsfot Print to PDF

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by