Create XLS File Via Python
Generate Excel XLS Files via your Python Applications without installing Microsoft Office®.
For a developer, who is trying to create XLS files via Python application? Aspose.Total for Python via Java API can help to automate the create process. It’s a full package of various APIs dealing different formats including Microsoft Office files and Images. Aspose.Cells for Python via Java API that is part of Aspose.Total for Python via Java package makes this generation process easy. Below is the process of creation. Moreover, developers can easily enhance the application for modification of XLS file. To update XLS file using Python process is same except that it requires existing file as parameter while creating the Workbook object.
How to Create XLS File in Python
- Create new Workbook class object having FileFormatType as parameter
- Get the access of required Worksheet using getWorksheets().get(index) method
- Insert data in the accessed cell using Worksheet.getCells().get(indexValue).putValue() method
- Save the document as .xls file using save() by passing the file with path as the parameter
Creation Requirements
- For XLS generation, reference APIs within the project directly from PyPI ( Aspose.Cells )
- Or use the following pip command
pip install aspose.cells
- Moreover, Download the API package from the downloads section
Create XLS File in Python
# create a new XLSX workbook | |
workbook = Workbook(FileFormatType.XLSX) | |
worksheet = workbook.getWorksheets().get(0) | |
# Insert a string value to a cell | |
worksheet.getCells().get("C2").setValue("Image") | |
# set the 4th row height | |
worksheet.getCells().setRowHeight(3, 150) | |
# set the C column width | |
worksheet.getCells().setColumnWidth(3,50) | |
# add a picture to the D4 cell | |
index = worksheet.getPictures().add(3, 3, "aspose-cells-for-python.png") | |
# get the picture object | |
pic = worksheet.getPictures().get(index) | |
# save the Excel file | |
workbook.save("workbook_with_image.xlsx") |
Explore Options with Python
What is XLS File Format?
The Excel XLS file format is a widely used and well-known file format for storing spreadsheet data. It is associated with Microsoft Excel, which is one of the most popular spreadsheet software applications. XLS stands for “Excel Spreadsheet” and has been a standard file format for Excel since its early versions.
The XLS file format is binary-based, meaning that it stores data in binary form rather than using XML or text-based formatting. This makes it more efficient for storing and processing large amounts of data. XLS files can contain multiple worksheets, each consisting of cells organized in rows and columns. These cells can hold various types of data, including text, numbers, dates, formulas, and formatting.
Excel provides a wide range of features and functionalities within the XLS file format. Users can perform complex calculations using formulas, apply formatting options to enhance the visual appearance of data, create charts and graphs, and utilize various data analysis tools. Additionally, Excel supports macros, which are scripts that automate repetitive tasks or perform custom operations within the spreadsheet.
Over the years, Microsoft has introduced newer file formats like XLSX, which is based on XML and offers enhanced features and compatibility. However, the XLS format continues to be supported by Excel and can be opened and edited by newer versions of the software.
The XLS file format has become an industry standard, widely used in businesses, educational institutions, and personal applications for data analysis, reporting, financial modeling, and more. Its widespread adoption and compatibility make it a reliable choice for storing and sharing spreadsheet data.