Aspose.Cells for Python via Java is a Python API for creating, reading and writing documents within Microsoft Excel formats including XLS and XLSX. This API is part of Aspose.Total for Python via Java package. Moreover, Develpors can easily write code for inserting data, images, charts, pivot tables within worksheets and many other functionalities. Python API also supports features such as set various Formulas , convert text to columns, smart marker and dynamic formula options. Below are the few example codes to create and modify spreadsheets.
How to Create Excel Files using Python
Aspose.Cells for Python via Java API provides Workbook class that handles the creation of files. Process is simple. Create the Workbook class object and access the relevant Worksheet by providing its index. Use the putValue method to add the content in the accessed cell and finally call the save() method the save the document with specific name.
Code 1 - Create Simple Excel File
# create a new XLSX workbook | |
wb = Workbook(FileFormatType.XLSX) | |
# insert value in the cells | |
wb.getWorksheets().get(0).getCells().get("A1").putValue("Hello World!") | |
# save workbook as .xlsx file | |
wb.save("workbook.xlsx") |
Code 2 - Insert Images Within Microsoft Excel Documents
# 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") |