Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
855 B
1
Indexable
Never
@app.route('/convert', methods=['POST'])def convert_excel_to_pdf():    try:        file = request.files['file']    except KeyError:        return "No file selected", 400        if file.filename == '':        return "No selected file", 400        try:        # Load the Excel file using pyexcelerate        workbook = pyexcelerate.Workbook(file.read())        pdf_path = 'output.pdf'                # Save the Excel content as HTML        html_path = 'temp.html'        workbook.save_html(html_path)                # Convert HTML to PDF using pdfkit        pdfkit.from_file(html_path, pdf_path)                # Clean up temporary HTML file        os.remove(html_path)                # Send the PDF file for download        return send_file(pdf_path, as_attachment=True, attachment_filename='output.pdf')    except Exception as e:        return str(e), 500