How to convert .xls file (Microsoft excel) to pdf using matlab
Show older comments
Hi, In my matlab application, I'm creating new excel file. I would like to convert this file to pdf format using matlab. Can I ??
1 Comment
heroe
on 6 Nov 2026 at 12:40
Yes, you can easily convert an Excel file to PDF using MATLAB.
The most efficient and robust way to achieve this on Windows is by using MATLAB's ActiveX Control (COM Automation) to programmatically control Microsoft Excel and trigger its built-in PDF export feature.
% Define absolute paths (Excel requires full paths, not relative)
excelFile = 'C:\path\to\your\input_file.xlsx';
pdfFile = 'C:\path\to\your\output_file.pdf';
% 1. Start an Excel ActiveX server
hExcel = actxserver('Excel.Application');
% 2. Make Excel invisible so it runs quietly in the background
hExcel.Visible = 0;
% 3. Open the workbook
hWorkbook = hExcel.Workbooks.Open(excelFile);
try
% 4. Select the target worksheet (e.g., Sheet 1)
hWorksheet = hWorkbook.Sheets.Item(1);
% 5. Export the sheet to PDF format
% 'xlTypePDF' corresponds to the value 0
hWorksheet.ExportAsFixedFormat(0, pdfFile);
disp('Conversion successful!');
catch ME
warning('An error occurred during conversion: %s', ME.message);
end
% 6. Clean up: Close workbook and quit Excel to free memory
hWorkbook.Close(false);
hExcel.Quit();
delete(hExcel);
In Case, this process is not work for this kind of situation i prefer a dedicated tool like PDFChamp Excel to PDF.
Answers (1)
Julian
on 10 Jul 2012
0 votes
You could publish to PDF direct from MATLAB. Also, if you have the possibility to Print to PDF on your system and printing from Excel to PDF gives the format you need, you could use actxserver in MATLAB to control the Excel print to PDF.
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!