From a short trip that I took recently.
- Vasudev Ram - Online Python training and programming Signup to hear about new products and services I create. Posts about Python Posts about xtopdf My ActiveState recipes
jugad2 is Vasudev Ram's blog, tracking software innovation, both open source and proprietary, worldwide. I'm an independent developer with many years experience in many tech areas, and a Fellow at the Python Software Foundation. My biz site is www.dancingbison.com and I tweet @vasudevram .
# XLSXtoPDF.py # Program to convert the data from an XLSX file to PDF. # Uses the openpyxl library and xtopdf. # Author: Vasudev Ram - http://jugad2.blogspot.com # Copyright 2015 Vasudev Ram. from openpyxl import load_workbook from PDFWriter import PDFWriter workbook = load_workbook('fruits2.xlsx', guess_types=True, data_only=True) worksheet = workbook.active pw = PDFWriter('fruits2.pdf') pw.setFont('Courier', 12) pw.setHeader('XLSXtoPDF.py - convert XLSX data to PDF') pw.setFooter('Generated using openpyxl and xtopdf') ws_range = worksheet.iter_rows('A1:H13') for row in ws_range: s = '' for cell in row: if cell.value is None: s += ' ' * 11 else: s += str(cell.value).rjust(10) + ' ' pw.writeLine(s) pw.savePage() pw.close()And here is a screenshot of the PDF output in fruits2.pdf: