ExportAsFixedFormat not fitting to page

Viewed 33

I'm creating a script that creates multiple xlsx files at the end of the script it will transform those xlsx files into pdf's and then delete the xlsx files everything is currently working however if I open the xlsx files they are formatted correctly in a way that you can print them in one page however the pdf is separated into 2 pages can anyone help me fit everything to one? I'm using xlsxwriter to write and format the excel files, xlwings, and win32com to convert to pdf.

import time
import glob
import os
import xlwings as xw

files = []
for file in glob.glob("*.xlsx"):
    files.append(file)  
for file in files:
    print(file)
    app = xw.App(visible=False)
    book = xw.Book(f'{file}')
    sheet = book.sheets[0]
    current_work_dir = os.getcwd()
    pdf_path = os.path.join(current_work_dir, f"{file}.pdf")
    time.sleep(.5)
    book.api.ExportAsFixedFormat(0, pdf_path, IgnorePrintAreas=False)
    time.sleep(.5)
    book.close()
    app.kill()

while True:
    for file in glob.glob("*.xlsx"):
        if file == "":
            break
        else:
            os.remove(file)
0 Answers
Related