- msoffice2pdf 0.0.8
- Навигация
- Ссылки проекта
- Статистика
- Метаданные
- Сопровождающие
- Классификаторы
- Описание проекта
- msoffice2pdf 0.0.8
- Installation
- (Windons Only):
- (Ubuntu Only):
- Convert Excel XLS XLSX to PDF in Python
- Python Excel to PDF Converter#
- Convert Excel XLS to PDF in Python#
- Excel XLS to PDF in Python#
- Excel File#
- Converted PDF#
- Python XLS to PDF — Customized Conversion#
- Online Excel to PDF Converter Tool#
- Free Python Excel to PDF Converter#
- Conclusion#
- See Also#
- How to Convert Excel to PDF Using Python
- PSPDFKit API
- Step 1 — Creating a Free Account on PSPDFKit
- Step 2 — Obtaining the API Key
- Step 3 — Setting Up Folders and Files
- Step 4 — Writing the Code
- Code Explanation
- Output
- Final Words
- Convert Excel File to PDF in Python
- Approach
- Combining all code
- 3 responses to “Convert Excel File to PDF in Python”
msoffice2pdf 0.0.8
This package aims to convert Office file types to PDF using Microsoft Office or LibreOffice.
Навигация
Ссылки проекта
Статистика
Метаданные
Лицензия: MIT License
Требует: Python >=3.6
Сопровождающие
Классификаторы
- Environment
- Win32 (MS Windows)
- OSI Approved :: MIT License
- Microsoft :: Windows
- Unix
- Python :: 3
- Office/Business :: Office Suites
- Software Development
- Software Development :: Libraries
- Software Development :: Libraries :: Python Modules
- System :: Filesystems
- Text Processing :: General
- Utilities
Описание проекта
msoffice2pdf 0.0.8
This package aims to convert Microsoft Office file types to PDF. This lib uses the comtypes package which makes it easy to access and implement custom, dispatch-based COM interfaces or LibreOffice software.
For use in Windows environment and soft=0 Microsoft Office must be installed.
For use in Windows environment and soft=1 you need the latest version of LibreOffice(soffice) installed.
For Ubuntu(linux) environment it is only possible to use soft=1 , that is, LibreOffice(soffice).
Supported files: [«.doc», «.docx», «.xls», «.xlsx», «.ppt», «.pptx», «.txt», «.xml»]
Installation
pip3 install msoffice2pdf
(Windons Only):
- Delete all cache files from the folder below in case there is any error with Microsoft Office conversion: C:\Users\\AppData\Local\Programs\Python\Python39\Lib\site-packages\comtypes\gen
- For Windows Server
Step 1:
Start > Run > dcomcnfg.exe
Step 2:
Select: Computers -> My Computer -> Config DCOM -> Microsoft Word 97-2003 Documents -> Properties Tab general select level authentication to None Tab security select customize and add All Tab identify select this user and add Admin user and password
Step 3:
Select: Computers -> My Computer -> Config DCOM -> Microsoft Excel Application -> Properties Tab general select level authentication to None Tab security select customize and add All Tab identify select this user and add Admin user and password
Step 4:
Select: Computers -> My Computer -> Config DCOM -> Microsoft PowerPoint Application -> Properties Tab general select level authentication to None Tab security select customize and add All Tab identify select this user and add Admin user and password
Install LibreOffice last version:
(Ubuntu Only):
sudo add-apt-repository -y ppa:libreoffice/ppa
sudo apt-get install libreoffice libreoffice-style-breeze
Convert Excel XLS XLSX to PDF in Python
If you need to convert your Excel files to PDF format in Python, you might be looking for a high-fidelity and fast converter library. No need to worry because in this article, you will find out how to perform an accurate conversion of Excel XLS/XLSX to PDF without writing any complex Python code.
In the section below, you will learn how to convert an Excel file to PDF, customize Excel to PDF conversion, and use a free online Excel to PDF conversion tool.
Python Excel to PDF Converter#
For Excel to PDF conversion, we’ll use Aspose.Cells for Python. It is a powerful spreadsheet manipulation API that lets you create, process, and convert Excel files from within your Python applications. You can install the API using the following pip command.
Convert Excel XLS to PDF in Python#
The conversion of Excel files to PDF is as simple as pie using Aspose.Cells for Python. The following steps are required to save an Excel file in PDF format.
And that’s it. Let’s have a look at how to transform these steps into code and convert an Excel XLS/XLSX file to PDF in Python.
Excel XLS to PDF in Python#
The following are the steps to convert an Excel XLSX file to PDF using Python.
The following code sample shows how to convert an Excel XSLX file to PDF.
Excel File#
Converted PDF#
Python XLS to PDF — Customized Conversion#
Aspose.Cells for Python also allows you to customize the XLSX to PDF conversion using different options. For example, you can set PDF compliance, compression, gridlines style, number of pages per sheet, etc. for the converted PDF file. The PdfSaveOptions class is used to set these options.
The following are the steps to use advanced options in XLSX to PDF conversion in Python.
- Load the Excel XLSX file using the Workbook class.
- Create an instance of PdfSaveOptions class.
- Use PdfSaveOptions object to set options, e.g. set PDF compliance using PdfOptions.setCompliance(PdfCompliance) method.
- Save XLSX as PDF using Workbook.save(fileName, saveOptions) method.
The following code sample shows how to use advanced options in Excel XLSX to PDF conversion.
Online Excel to PDF Converter Tool#
Use our online Excel to PDF converter app, which is based on Aspose.Cells. This is a free app and you do not have to sign up for this.
Free Python Excel to PDF Converter#
You can get a free temporary license to use the API without evaluation limitations.
You can explore more about Aspose.Cells for Python via Java using the documentation. In case you would have any queries, contact us via our forum.
Conclusion#
In this article, you have learned how to convert Excel XLSX or XLS to PDF in Python. Furthermore, the advanced options to control the Python Excel to PDF conversion are also discussed with the help of the code sample. In addition, we have provided you with an online Excel to PDF converter tool, which is free and you can use it without any limitations.
See Also#
How to Convert Excel to PDF Using Python
Vyom Srivastava
In this post, you’ll learn how to convert Excel files to PDFs in your Python application using PSPDFKit’s XLSX to PDF Python API. With our API, you can convert up to 100 PDF files per month for free. All you need to do is create a free account to get access to your API key.
PSPDFKit API
Document conversion is just one of our 30+ PDF API tools. You can combine our conversion tool with other tools to create complex document processing workflows. You’ll be able to convert various file formats into PDFs and then:
- Merge several resulting PDFs into one
- OCR, watermark, or flatten PDFs
- Remove or duplicate specific PDF pages
Once you create your account, you’ll be able to access all our PDF API tools.
Step 1 — Creating a Free Account on PSPDFKit
Go to our website, where you’ll see the page below, prompting you to create your free account.
Once you’ve created your account, you’ll be welcomed by the page below, which shows an overview of your plan details.
As you can see in the bottom-left corner, you’ll start with 100 documents to process, and you’ll be able to access all our PDF API tools.
Step 2 — Obtaining the API Key
After you’ve verified your email, you can get your API key from the dashboard. In the menu on the left, click API Keys. You’ll see the following page, which is an overview of your keys:
Copy the Live API Key, because you’ll need this for the Excel to PDF API.
Step 3 — Setting Up Folders and Files
Now, create a folder called excel_to_pdf and open it in a code editor. For this tutorial, you’ll use VS Code as your primary code editor. Next, create two folders inside excel_to_pdf and name them input_documents and processed_documents .
Now, copy your Excel file to the input_documents folder and rename it to document.xlsx . You can use our demo document as an example.
Then, in the root folder, excel_to_pdf , create a file called processor.py . This is the file where you’ll keep your code.
Your folder structure will look like this:
excel_to_pdf ├── input_documents | └── document.xlsx ├── processed_documents └── processor.py
Step 4 — Writing the Code
Open the processor.py file and paste the code below into it:
import requests import json instructions = < 'parts': [ < 'file': 'document' > ] > response = requests.request( 'POST', 'https://api.pspdfkit.com/build', headers = < 'Authorization': 'Bearer YOUR API KEY HERE' >, files = < 'document': open('input_documents/document.xlsx', 'rb') >, data = < 'instructions': json.dumps(instructions) >, stream = True ) if response.ok: with open('processed_documents/result.pdf', 'wb') as fd: for chunk in response.iter_content(chunk_size=8096): fd.write(chunk) else: print(response.text) exit()
ℹ️ Note: Make sure to replace YOUR_API_KEY_HERE with your API key.
Code Explanation
In the code above, you first import the requests and json dependencies. After that, you create the instructions for the API call.
You then use the requests module to make the API call, and once it succeeds, you store the result in the processed_documents folder.
Output
To execute the code, use the command below:
Once the code has been executed, you’ll see a new processed file under the processed_documents folder called result.pdf .
The folder structure will look like this:
excel_to_pdf ├── input_documents | └── document.xlsx ├── processed_documents | └── result.pdf └── processor.py
Final Words
In this post, you learned how to easily and seamlessly convert Excel files to PDF documents for your Python application using our Excel to PDF Python API.
You can integrate these functions into your existing applications. With the same API token, you can also perform other operations, such as merging several documents into a single PDF, adding watermarks, and more. To get started with a free trial, sign up here.
Convert Excel File to PDF in Python
In this tutorial, we will learn to convert Excel Files to PDF in python. We will learn a bit about PyWin32 library.
PyWin32 is a Python library for Microsoft Windows that enables the Win32 application programming interface (API) features on Python. To install the PyWin32 library, open command prompt/ Terminal and write
Approach
Let’s see a fundamental approach to convert Excel files (.xlsx or .xls format) to PDF format.
- Create a COM object using Dispatch() function.
- Read the Excel file pass “Excel.Application” inside the Dispatch function.
- Write Excel file path.
- Convert Excel into PDF format using ExportAsFixedFormat() and pass the path to which you want to save the pdf file.
Import Client submodule from win32com library
# Import Library from win32com import client
client.Dispatch() function will help to extract the excel application from windows system. Workbook methods will help to read the excel file.
# Opening Microsoft Excel excel = client.Dispatch("Excel.Application") # Read Excel File sheets = excel.Workbooks.Open('Enter Excel file path') work_sheets = sheets.Worksheets[0]
Converting Excel file to PDF file. ExportAsFixedFormat() method is used to convert a workbook into either PDF format.
# Converting into PDF File work_sheets.ExportAsFixedFormat(0, 'Enter PDF file path')
Combining all code
# Import Library from win32com import client # Opening Microsoft Excel excel = client.Dispatch("Excel.Application") # Read Excel File sheets = excel.Workbooks.Open('Enter Excel file path') work_sheets = sheets.Worksheets[0] # Converting into PDF File work_sheets.ExportAsFixedFormat(0, 'Enter PDF file path')
We have successfully converted Excel file to PDF file format using Python.
3 responses to “Convert Excel File to PDF in Python”
I have tried with this method but is is not working for xlsm . Could you please provide a efficent python example to convert excel workbook xlsm into Pdf?
its not working is there any other ways facing an error :No module named ‘win32com’
changes the module still facing the errorfrom flask import Flask, send_file,render_template
from openpyxl import load_workbook
from fpdf import FPDF app = Flask(__name__)
@app.route(“/”)
def index():
return render_template(“Original.html”) @app.route(‘/download’)
def download_file():
create_pdf()
path = “Project.pdf”
send_file(path, as_attachment=True) def create_pdf(): workbook = load_workbook(‘Project.xlsx’)
sheet = workbook.active 23
pdf = FPDF()
pdf.add_page() for row in sheet.iter_rows():
for cell in row:
pdf.set_font(‘Arial’, ‘B’, 16)
pdf.cell(50, 10, str(cell.value)) pdf.output(‘example.pdf’, ‘F’) if __name__ == ‘__main__’:
app.run()