Insert comments in ODS file via Python
Build your own Python application to manipulate comments & authors in document files using server-side APIs.
Insert comments in ODS File Using Python
With Aspose.Cells for Python library, you can easily insert comments in ODS file programmatically with a few lines of code. Aspose.Cells for Python is capable of building cross-platform applications with the ability to generate, modify, convert, render and print all Excel files. Python Excel API not only convert between spreadsheet formats, it can also render Excel files as images, PDF, HTML, ODS, CSV, SVG, JSON, WORD, PPT and more, thus making it a perfect choice to exchange documents in industry-standard formats. You may install Aspose.Cells for Python via Java from pypi, use command as:$ pip install aspose-cells
.System Requirements
Aspose.Cells for Python is supported on all major operating systems. Just make sure that you have the following prerequisites.
How to insert comments in ODS file via Python
You need aspose.cells.dll to try the code in your environment.
- Load ODS file by creating an instance of Workbook
- Insert comments to the Worksheet in a Cell
- Save the workbook
In Office 365, comments are for conversations, you can use the following Python code to insert and remove comments in ODS file.
Python sample code to Insert and remove comments in ODS file
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, SaveFormat | |
# Load Source Excel file | |
workbook = Workbook("Test.ods") | |
# Add the comment object to cell A1 of first worksheet | |
comments = workbook.getWorksheets().get(0).getComments() | |
commentIndex = comments.add("A1") | |
comment = comments.get(commentIndex) | |
# Add comments, with the author object | |
commentAuthors = workbook.getWorksheets().getThreadedCommentAuthors() | |
author1Index = commentAuthors.add("Mr.Yang", "author1", "OV1") | |
author2Index = commentAuthors.add("Johnson", "author2", "OV2") | |
author1 = commentAuthors.get(author1Index) | |
author2 = commentAuthors.get(author2Index) | |
comment.getThreadedComments().add("Where did we get this xlsx file?", author1) | |
comment.getThreadedComments().add("It came from Contoso.", author2) | |
# Save file with comment (check with office 365). | |
workbook.save("comment-added.ods") | |
# Remove one comment from cell A1 | |
comment.getThreadedComments().removeAt(1) | |
# Save the book again to compare (check with office 365). | |
workbook.save("comment-removed.ods") | |
jpype.shutdownJVM() | |
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
workbook = Workbook("input.ods")
sheets = workbook.getWorksheets()
for sheet in sheets:
sheet.getComments().clear()
workbook.Save("output.ods")
jpype.shutdownJVM()
ODS What is ODS File Format?
Files with .ods extension stand for OpenDocument Spreadsheet Document format that are editable by user. Data is stored inside ODF file into rows and columns. It is XML-based format and is one of the several subtypes in the Open Document Formats (ODF) family. The format is specified as part of the ODF 1.2 specifications published and maintained by OASIS. A number of applications on Windows as well as other operating systems can open ODS files for editing and manipulation including Microsoft Excel, NeoOffice and LibreOffice. ODS files can also be converted into other spreadsheet formats as well like XLS, XLSX and others by different applications.
Read More