Borrar filtros
Borrar filtros

How to save an Excel sheet as PDF through MATLAB?

31 visualizaciones (últimos 30 días)
Ziggy Zigg
Ziggy Zigg el 3 de Nov. de 2012
Respondida: Intissar El Bouanani el 10 de Ag. de 2023
I am using the following code:
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s','C:\test.xlsx'));
hWorksheet = hWorkbook.Sheets.Item(1);
hRange = hWorksheet.Range('A1:O10');
hRange.ExportAsFixedFormat('xlTypePDF','test_out.pdf');
The Excel ActiveX server allows me to do the usual stuff, but the last line doesn't do anything. Neither does it throw any error.
Does anyone know how to do this?
  1 comentario
Praveen
Praveen el 28 de Dic. de 2016
hRange.ExportAsFixedFormat('xlTypePDF','test_out.pdf'); In this code give the path name, it works.. For example 'C:\test_out.pdf' instead of test

Iniciar sesión para comentar.

Respuesta aceptada

Cel Kulasekaran
Cel Kulasekaran el 13 de En. de 2015
Editada: Cel Kulasekaran el 13 de En. de 2015
First, set the print area within the workbook itself, then you'll need to call ExportAsFixedFormat on the worksheet or workbook object. You cannot call it on the range object. Hope this helps, see below:
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s','C:\test.xlsx'));
hWorksheet = hWorkbook.Sheets.Item(1);
% print this sheet to PDF
hWorksheet.ExportAsFixedFormat('xlTypePDF','C:\test_out.pdf');
  5 comentarios
Garrett Cassidy
Garrett Cassidy el 27 de En. de 2021
Is there a way to make it save 'Entire workbook'? When I manualy save as PDF I can click 'Options' then save 'Entire workbook' this saves each sheet as a page in the PDF.
Garrett Cassidy
Garrett Cassidy el 27 de En. de 2021
Answer my own question:
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s','C:\test'));
% Pring the workbook
hWorkbook.ExportAsFixedFormat('xlTypePDF','C:\test_out.pdf');

Iniciar sesión para comentar.

Más respuestas (1)

Intissar El Bouanani
Intissar El Bouanani el 10 de Ag. de 2023
it is possible to print the selected field in one page

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by