OpenOffice is a free, open source office suite that integrates APIs that allow developers to develop in different languages. Python-UNO lets you use OpenOffice in a Python environment. This article briefly introduces the use of Python-UNO. OpenOffice.org provides a powerful and compatible solution as a free open source Office suite, which has established a good reputation. According to it, the number of downloads has exceeded 50 million times, and it can run on multiple platforms. It's hard for developers to ignore such a project, which is why OpenOffice.org provides an API that allows developers to use OpenOffice.org in different locales. Of course, you may have a hard time imagining that Python is also included in the list of languages ​​allowed by OpenOffice.org, because Python makes things "too simple". And Python-UNO just makes everything possible. OpenOffice.org leverages Universal Network Objects (UNO). This technology allows OpenOffice.org to work with components written in different languages. Python-UNO provides a Python interface to use it. Python-UNO is included in OpenOffice.org, so there is no need to install anything else. Unfortunately, this has a drawback. Since the Python version included in OpenOffice.org 2.0 is 2.3.5, the recently added features are not available. Of course, some people are working hard to solve this problem, making OpenOffice.org compatible with newer versions of Python. There are also some linux distributions that have Python-UNO configured to work with Python by default, such as Ubuntu. You can run Python and try to import the uno module to see if it works. If you can, let's start using Python-UNO. Connect to OpenOffice.org First of all, let's connect OpenOffice.org first, only a few small steps, very simple. Before connecting to OpenOffice.org, we must make sure it is listening. This includes passing a string to it when it is started. First, make sure that OpenOffice.org is completely logged out (if you are using a Windows system, you also need to quit OpenOffice.org from the system disk), then open the terminal, switch to the OpenOffice.org installation directory, and go to the directory where the executable files are located. Next, we'll open the OpenOffice.org Writer, passing in a parameter that allows OpenOffice.org to listen to the connection we're going to do later: OpenOffice.org opened this way is no different from the normal way to open. The parameters we passed create a UNO receiver that listens to us for connection via Python-UNO and OpenOffice.org APIs. Open the directory where the program is located in a new window, find the Python version of OpenOffice.org and execute it, which will take you into an interactive interpreter. Also, if you know that your Linux distribution has Python-UNO included by default in Python, you can open Python as usual. The first step is of course to import the Python-UNO module, the name is uno: The first thing you have to do is import a local component context. If you want to figure out exactly what the component context is and what it does, you can google it yourself. Here, let's explain it a bit. A context manager consists of a service manager and related objects, just as an environment in which the service manager exists. What is the service manager? As the name suggests, the Service Manager is used to manage services. Its name is a simple definition of its function. Finally explain the service. A service is an object that is bound to a specific set of tasks. For example, there is a specific service responsible for loading and managing documents, and another for connecting to OpenOffice.org settings. Services are managed by a service manager, which exists in a component context. Of course, things are not that simple, but here we don't need to use other knowledge. After a brief introduction to the concepts of component context, service manager and services, let's move on and create a local component context. We will use it later to get the component context of OpenOffice.org: Now we have a local component context. Next, we also need to get the UnoUrlResolver service. This service is used to connect to OpenOffice.org. We need to use the service manager's createInstanceWithContext method, which is in the local.ServiceManager. The parameters are set to the name of the service we want, and the context instance: This way we can connect to OpenOffice.org. Quite simply, just call a method and set the parameters to the parameters we passed when we started OpenOffice.org Writer. After that, we can use the component context of OpenOffice.org to manipulate it through the OpenOffice.org API: The parameters are only slightly different from the parameters when starting OpenOffice.org, except that the "StarOffice.ComponentContext" is added to request the component context of OpenOffice.org. We also added a protocol (uno) at the top. Now we are connected to OpenOffice.org. Use desktop services Now that we can use the OpenOffice.org API, let's take a look at the file. I have already had a service that is responsible for the current documentation. The name of this service is "com.sun.star.frame.Desktop". With this service we can play the OpenOffice.org Writer document created when we started OpenOffice.org. First, we need to get the service using the createInstanceWrithContext method we mentioned earlier. The parameters are the service name and context. Very good, now we have the Desktop service, and we have the ability to load documents and manage documents. Let's try to modify the current document first. Use the getCurrentComponent method: Before modifying the document, you must first create a cursor cursor. this is very simple: With the cursor, we can add some content to the document. Try adding a simple string first: After executing the above code, you should see an extra line of text in the document. Add a line break to add a line break to the document: Simple indentation is also easy to implement. Just add an indentation "t": Of course, repetitively adding text is not valid, which is why we want to manipulate the cursor. For example, we want to put a big one font. This is easily done with cursor properties. UNO objects include properties that can be modified with very simple method calls. Before we change the cursor font size, we first get the current font size: As you can see, the name of the font size attribute is called "CharHeight". Calling another method can modify this property. Let's change the font size to 20: Now that the font size has changed, we can add some text with a font size of 20 into the document: Not only can the text size change, but basically everything can change. Let's change the font and font weight: Talking about the form Forms are often used in the work, let us look at how to use the form in Python-UNO. Open a new document first: Start using the form on a new, blank document. The table we have to do contains five countries, as well as the population of each country. So, this table will have 6 rows, one of which is the header; there are 2 columns. Here is the command to create a table: Of course, we need to pass the number of rows and columns of the table to population. Here is the initialization function: If you look at the open document, you can't see anything. You have to insert this form to see it. The insertion of a table is similar to a text insertion: Now you can start inserting the table contents. It consists of two steps that describe the name of each cell and then insert the text. The first row of the table is named "A" and the first column is named "1". This naming pattern lasts until the end of the table. Each cell name is a combination of row name and column name. Insert the header first: Next, you can fill in the country information: in conclusion OpenOffice.org is a fairly powerful tool, especially as it provides APIs that can be called in many different languages. Fortunately, these languages ​​include Python, Python-UNO. Python developers can import this module and create a local component context that can be used to connect to the OpenOffice.org context. Once connected, the developer can modify the document. Although this article only covers inserting text and tables and changing font properties, the OpenOffice.org API also provides a lot of functionality. There are many ways to modify text and tables. Although we only talked about OpenOffice.org's Writer software, there are other applications for the OpenOffice.org suite.
UCOAX offers LVDS Assemblies service for oversea customer.
Lvds Cable Assembly,Lvds Cables,Lvds Cable Extension,Lvds Cable Assembly Function UCOAX , https://www.ucoax.com