Home > Software engineering >  Turning a .xlsx into multiple PDFs
Turning a .xlsx into multiple PDFs

Time:01-31

I have a python script that takes an .xlsx file with multiple worksheetes and splits each one of them into a seperate PDF with the worksheet name as the new file name.

import openpyxl
import pandas as pd
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt

def xlsx_to_pdf(filename):
    wb = openpyxl.load_workbook(filename)
    for ws in wb:
        df = pd.DataFrame(ws.values)
        with PdfPages(f"{ws.title}.pdf") as pdf:
            fig, ax = plt.subplots()
            ax.axis('tight')
            ax.axis('off')
            the_table = ax.table(cellText=df.values,
                                  colLabels=df.columns,
                                  cellLoc='center',
                                  loc='center')
            pdf.savefig(fig, bbox_inches='tight')

xlsx_to_pdf("Provisionsabrechnung.xlsx")

The only problem I have is that the lines on the tabel it creates are really thick and the text is super small. enter image description here

  • Related