<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tutolibro.org</title>
	<atom:link href="https://tutolibro.org/feed/" rel="self" type="application/rss+xml" />
	<link>https://tutolibro.org</link>
	<description>Free online tutorials</description>
	<lastBuildDate>Thu, 27 Nov 2025 22:59:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://tutolibro.org/wp-content/uploads/2020/02/cropped-logo_mini-32x32.png</url>
	<title>tutolibro.org</title>
	<link>https://tutolibro.org</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">173775150</site>	<item>
		<title>Assign Your Python Macro to a Button in LibreOffice Calc</title>
		<link>https://tutolibro.org/2025/11/26/assign-your-python-macro-to-a-button-in-libreoffice/</link>
					<comments>https://tutolibro.org/2025/11/26/assign-your-python-macro-to-a-button-in-libreoffice/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Wed, 26 Nov 2025 16:03:15 +0000</pubDate>
				<category><![CDATA[Calc]]></category>
		<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[calc]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[libreoffice]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1555</guid>

					<description><![CDATA[Assign the macro to a LibreOffice Control Button. When you write a macro within libreOffice, you will quickly realise something. It&#8217;s not really convenient to execute macros through the Macro Manager. This is because you need to access that menu,...<br /><a class="read-more-button" href="https://tutolibro.org/2025/11/26/assign-your-python-macro-to-a-button-in-libreoffice/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<h4 class="wp-block-heading" id="top"> Assign the macro to a LibreOffice Control Button.</h4>



<p id="switch">When you write a macro within libreOffice, you will quickly realise something. It&#8217;s not really convenient to execute macros through the Macro Manager. This is because you need to access that menu, and it takes a few clicks to do so. (Quickest way to access the APSO Macro manager being [Alt] + [Shift] + [F11]). Creating a button on your spreadsheet is easy. You can assign this button to your macro. When you click on the button, it will execute the macro.<br>So first we&#8217;ll <strong><a href="#switch">Switch to Design Mode</a></strong>. This allows us to <strong><a href="#button">create a button</a></strong> on the spreadsheet. Then, we&#8217;ll <strong><a href="#assign">assign the python macro</a></strong> to this button.</p>



<p><strong><span style="text-decoration: underline;">Switch to Design Mode</span></strong>:                                                                                                            (<a href="#top">Back to Top</a>)</p>



<p>The first step is to set the document to &#8216;Design Mode&#8217; . Select &#8216;Design Mode&#8217; From &#8216;Menu Tools/Forms/Design Mode&#8217;.</p>



<figure class="wp-block-image size-full" id="button"><img fetchpriority="high" decoding="async" width="555" height="463" src="https://tutolibro.org/wp-content/uploads/2025/11/lopy-designMode-1.png" alt="" class="wp-image-1606" srcset="https://tutolibro.org/wp-content/uploads/2025/11/lopy-designMode-1.png 555w, https://tutolibro.org/wp-content/uploads/2025/11/lopy-designMode-1-300x250.png 300w" sizes="(max-width: 555px) 100vw, 555px" /></figure>



<p><strong><span style="text-decoration: underline;">Create a button</span></strong>:                                                                                                            (<a href="#top">Back to Top</a>)<br>Then simply by clicking on Menu &#8216;<strong>Insert>Form Controls>Push Button&#8217;</strong>:</p>



<figure class="wp-block-image size-full"><img decoding="async" width="492" height="730" src="https://tutolibro.org/wp-content/uploads/2025/11/lopy-InsertPushButtonMenu.png" alt="" class="wp-image-1605" srcset="https://tutolibro.org/wp-content/uploads/2025/11/lopy-InsertPushButtonMenu.png 492w, https://tutolibro.org/wp-content/uploads/2025/11/lopy-InsertPushButtonMenu-202x300.png 202w" sizes="(max-width: 492px) 100vw, 492px" /></figure>



<p>Once you have the little cross to insert the button, click for the button&#8217;s upper left corner. Then hold and release where you want the bottom right corner of the button.</p>



<figure class="wp-block-image size-large is-resized" id="assign"><img decoding="async" width="124" height="84" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc11.png" alt="" class="wp-image-858"/></figure>



<p><strong><span style="text-decoration: underline;">Assign the python macro</span></strong><span style="text-decoration: underline;">:</span>                                                                                                            (<a href="#top">Back to Top</a>)<br>Once you have the button displayed, right click on it and select &#8216;Control&#8230;&#8217;</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="241" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12.png" alt="" class="wp-image-859" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12.png 241w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12-194x300.png 194w" sizes="auto, (max-width: 241px) 100vw, 241px" /><figcaption class="wp-element-caption">Select &#8216;Control&#8217; from the new Button contextual menu</figcaption></figure>



<p>Then in the window &#8216;Properties&#8217; select the &#8216;Events&#8217; tab, scroll down a bit to find in the list of events the one called &#8216;Mouse button pressed&#8217;. On the right of this &#8216;Mouse button pressed&#8217; entry click on the button &#8216;[&#8230;]&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="564" height="430" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13.png" alt="" class="wp-image-860" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13.png 564w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13-300x229.png 300w" sizes="auto, (max-width: 564px) 100vw, 564px" /></figure>



<p>A window named  &#8220;Assign Action&#8217; pops up, click on the button &#8216;[Macro]&#8217; on the right hand side of this window.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="592" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14.png" alt="" class="wp-image-861" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14.png 592w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14-300x189.png 300w" sizes="auto, (max-width: 592px) 100vw, 592px" /><figcaption class="wp-element-caption">Assign a macro to a button</figcaption></figure>



<p>You should then get the &#8216;Macro Selector&#8217; with your Macro Libraries. Simply go to the library where your macro is saved and select the macro &#8216;HelloWorld&#8217;,then press &#8216;OK&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="722" height="202" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973.png" alt="" class="wp-image-862" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973.png 722w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973-300x84.png 300w" sizes="auto, (max-width: 722px) 100vw, 722px" /><figcaption class="wp-element-caption">Select the macro from Macro Selector</figcaption></figure>



<p>Then &#8216;OK&#8217; again in &#8216;Assign Macro&#8217; window, than close the &#8216;Properties&#8217; window.<br>The last thing to do is exit the &#8216;Design&#8217; mode. This allows you to click on the button. Do that by going to &#8216;Tools&gt;Forms&gt;Design Mode&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="461" height="541" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17.png" alt="" class="wp-image-864" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17.png 461w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17-256x300.png 256w" sizes="auto, (max-width: 461px) 100vw, 461px" /><figcaption class="wp-element-caption">Set design mode off</figcaption></figure>



<p>And now when you click on the button&#8230; tada&#8230;<br>If you get this ERROR!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="546" height="255" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16.png" alt="" class="wp-image-863" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16.png 546w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16-300x140.png 300w" sizes="auto, (max-width: 546px) 100vw, 546px" /><figcaption class="wp-element-caption">Error: missing argument</figcaption></figure>



<p>The function HelloWorld requires all information from LibreOffice Context to work. This information is needed in the form of an argument. So we need to pass the argument &#8216;*args&#8217; in your function called by the Push Button.<br>For example in the program HelloWorld done in a previous post, in your code instead of:<br><code>def HelloWorld():</code><br>You should have:<br><code>def HelloWorld(*args):</code><br>Save your program again and then when you press on the button the cell A1 will display &#8216;Hello World!&#8217; !!!</p>



<p>So there is the final version of the macro:</p>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="wp-block-code"><code># Created by Gweno 16/08/2019 for tutolibro.tech
# This program displays 'Hello World!" in cell A1 of the 
# current Calc document.

def HelloWorld(*args):
    """Write 'Hello World!' in Cell A1"""
    
# get the doc from the scripting context 
# which is made available to all scripts
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent()
    
# access the active sheet
    active_sheet = model.CurrentController.ActiveSheet

# write 'Hello World' in A1
    active_sheet.getCellRangeByName("A1").String = "Hello World!"</code></pre>



<p>You can clone or download this code from gitHub <a href="https://github.com/Gweno/tutolibro.tech/tree/master/lopy/part2">here</a>.</p>



<hr class="wp-block-separator has-css-opacity"/>



<h3 class="wp-block-heading">Good luck! and leave a comment if you are having problem to have this macro to work.</h3>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-default"/>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/11/26/assign-your-python-macro-to-a-button-in-libreoffice/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1555</post-id>	</item>
		<item>
		<title>LibreOffice Calc &#038; Python Programming: Part 1 – Requirements</title>
		<link>https://tutolibro.org/2025/11/26/libreoffice-calc-python-programming-part-1-requirements/</link>
					<comments>https://tutolibro.org/2025/11/26/libreoffice-calc-python-programming-part-1-requirements/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Wed, 26 Nov 2025 15:29:24 +0000</pubDate>
				<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1570</guid>

					<description><![CDATA[I am finally starting to write this tutorial. Thanks for your patience, and thanks to Nukool for your comment, it really gave me motivation to write this course. In this Part 1 of LibreOffice Calc &#38; Python programming tutorial we...<br /><a class="read-more-button" href="https://tutolibro.org/2025/11/26/libreoffice-calc-python-programming-part-1-requirements/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p>I am finally starting to write this tutorial. Thanks for your patience, and thanks to Nukool for your comment, it really gave me motivation to write this course.</p>



<p>In this Part 1 of LibreOffice Calc &amp; Python programming tutorial we are looking at:</p>



<ul class="wp-block-list">
<li>some <strong><a href="#sofware">Software</a></strong> you need</li>



<li>the <strong><a href="#apso">APSO extension</a></strong> that&#8217;ll make things much easier</li>



<li>an <strong><a href="https://tutolibro.org/2019/07/26/libreoffice-calc-python-programming-part-1-requirements/">extra step for Linux</a></strong> users</li>



<li>useful <strong><a href="https://tutolibro.org/2019/07/26/libreoffice-calc-python-programming-part-1-requirements/">documentation</a></strong></li>



<li><strong><a href="https://tutolibro.org/2019/07/26/libreoffice-calc-python-programming-part-1-requirements/">further notes</a></strong></li>
</ul>



<h3 class="wp-block-heading" id="software">Software</h3>



<h4 class="wp-block-heading">LibreOffice</h4>



<p>You will of course need LibreOffice, you can download the <a href="https://www.libreoffice.org/">latest version here.</a><br>LibreOffice is normally shipped with a PyUNO bridge. This allows it to bind its components with the Python language. It also makes it possible to program LibreOffice with Python. (see at end of this article if you&#8217;re using a Linux ).</p>



<h4 class="wp-block-heading"><strong>Python</strong> 3</h4>



<p>You also need the Python 3 programming language on your computer.<br>It may be installed already. For now I let you do it yourself, but I might write a quick help later. Just web search for &#8216;python 3&#8217; for your Operating system. </p>



<h4 class="wp-block-heading"><strong>IDE / Text Editor</strong></h4>



<p>You will also need a text editor or even better an IDE (Integrated Development Environment) to write your python program. The advantage of an IDE versus a simple text editor is that it offers tools to organise your codes, an IDE can also makes it easier to spot errors and offers all sort of features to speed up and ease coding like word auto-completion, search and replace.<br>If you are a programmer you may already have a preference for a simple editor or a clever one. I am using a free open-source IDE called <a href="https://www.geany.org/"><strong>geany</strong></a>, but other popular ones are Eclipse, code::block and the famous Microsoft Visual Studio. They all have their pros and cons, here is <a href="https://pypl.github.io/IDE.html">the Top 20 of the most popular ones</a>. Geany is perfect for &#8216;small jobs&#8217; like we are going to do, but again it&#8217;s also fine to use a text editor like notepad.</p>



<h4 class="wp-block-heading">JRE install</h4>



<p id="apso">If your computer does not have Java Runtime Environment already you will need to install it through the Oracle website. You can also follow instruction <a href="https://java.com/en/download/manual.jsp">here</a>. JRE is indeed required to be able to use macros within LibreOffice.</p>



<h3 class="wp-block-heading"><strong>APSO extension</strong></h3>



<p>By default LibreOffice Python Macros are independent from any LibreOffice file. So to execute a python program within a LibreOffice Calc Spreadsheet for example you would need to go in Tools/Macro/Run Macro and select the python program from a list corresponding to a folder on your Hard drive. And this list, for example &#8216;MyMacro&#8217;, would be accessible for any LibreOffice file (Calc, Text, Base, etc&#8230;). This is great but not helpful when you want a particular python program to be used specifically for a particular file. <br>APSO is a LibreOffice extension that helps with organising Python Macros within your LibreOffice files. You just need to download <a href="https://extensions.libreoffice.org/extensions/apso-alternative-script-organizer-for-python">the APSO extension here</a> and then install the tool via Tools/Extensions Manager. One great advantage of APSO is its EditorKicker that you can set up to use your preferred text editor or IDE to edit your Python program.<br>One last note about using APSO, although the programs themselves are saved in the same folders than all other programs, the ones you choose to be embed in a particular file will be linked to that file, or rather for example LibreOffice calc file will have a link to the  python program in its parameters and you will be able to see your program attached to LibreOffice documents currently opened.</p>



<h3 class="wp-block-heading" id="linux"><strong>Extra step for linux</strong></h3>



<p>I had to do one extra step when I was using LibreOffice 5 under Linux mint Operating System: adding some library. Without it it was not possible to do any Python macros within LibreOffice. This is an easy step, just open a terminal, type and execute:</p>



<p>sudo apt-get install libreoffice-script-provider-python</p>



<p>It will be the same for Ubuntu. For other linux distro you will need to check yourself but it&#8217;d be similar using the in-house package manager.</p>



<h3 class="wp-block-heading" id="doc"><strong>Documentation</strong></h3>



<p>It is not easy to find helpful documentation for programming Python Macros for LibreOffice. Firstly it&#8217;s hard to find a site or forum that have real documentation about using Python for LibreOffice, and secondly the tasks explained are usually too complicated for a beginner. However this is the best place I found so far with a list of links to Python program examples. You will not that most of the examples are using a Python library created by &#8216;Danny&#8217;.</p>



<h3 class="wp-block-heading" id="notes"><strong>Further notes</strong></h3>



<p>In my tutorial we will create everything from scratch and develop simple and useful functions.<br>I still haven&#8217;t decided what topic to cover to illustrate this tutorial. I am hesitating between continuing the <a href="https://tutolibro.org/2018/05/02/tutorial-make-a-time-schedule-in-libreoffice-using-formulas-and-a-simple-macro/">time schedule</a>, starting invoice manager or a garden planner.<br>If you have any preference please let me know in your comment.<br></p>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/11/26/libreoffice-calc-python-programming-part-1-requirements/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1570</post-id>	</item>
		<item>
		<title>Embedding vs. Storing Python Macros in LibreOffice</title>
		<link>https://tutolibro.org/2025/11/19/embedding-vs-storing-python-macros-in-libreoffice/</link>
					<comments>https://tutolibro.org/2025/11/19/embedding-vs-storing-python-macros-in-libreoffice/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Wed, 19 Nov 2025 23:22:50 +0000</pubDate>
				<category><![CDATA[Calc]]></category>
		<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[calc]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[libreoffice]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1580</guid>

					<description><![CDATA[This article helps you decide whether to embed your python macro in the file. It also explores saving it in a macro repository. With the APSO add-on (see previous article) you can embed your macro within the LibreOffice File. This...<br /><a class="read-more-button" href="https://tutolibro.org/2025/11/19/embedding-vs-storing-python-macros-in-libreoffice/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<ul class="wp-block-list">
<li></li>
</ul>



<p>This article helps you decide whether to embed your python macro in the file. It also explores saving it in a macro repository.</p>



<p>With the APSO add-on (<a href="https://tutolibro.org/2019/07/26/getting-started-with-libreoffice-calc-and-python/" data-type="post" data-id="563">see previous article</a>) you can embed your macro within the LibreOffice File. This can be useful for example when you want to send your LibreOffice file with the Python Macro. A downside is that the Python macro will not be accessible outside of the LibreOffice file you sent. So you will need to open the LibreOffice file. Then open the Python Macro organiser. This is necessary to edit the Python program.</p>



<p>There are alternatives to embedding the Python program. You can place it in an organized directory while still using APSO. This lets you re-use it for any other LibreOffice document. You can also edit the program without opening the LibreOffice document if you open it from the relevant folder. If you want to send your LibreOffice Document to someone, there is a trade-off. You will also need to send the Python macro.</p>



<p>I am in favor of keeping programs in a tidy manner. This approach allows me to re-use them across many different files. But the choice is entirely up to you. I hope </p>



<p>To illustrate these 2 cases, let&#8217;s have a look at an example:</p>



<p>I have a file called &#8220;<strong>HelloWorld.ods</strong>&#8221; and two Python files: the first one is called &#8220;<strong>HelloWorld.py</strong>&#8221; and the other file is called &#8220;<strong>Testing.py&#8221;</strong>. The first python file is embedded in the LibreOffice file, the second is in the shared Python Scripts directory.</p>



<p class="has-text-align-left">In the first case scenario, after opening HelloWorld.ods, I can go to the Python Script Organizer, in Tools&gt;Macro&gt;Organize Python Scripts (shortcut Alt+Shift+F11) from the APSO extension. Alternatively I can use the LibreOffice Standard Macro Organiser in Tools&gt;Macro&gt;Organise Macros&gt;Python&#8230;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="543" height="672" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01.png" alt="" class="wp-image-848" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01.png 543w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01-242x300.png 242w" sizes="auto, (max-width: 543px) 100vw, 543px" /></figure>



<p class="has-text-align-left"><br>In the Python Scripts Organiser you will see that your Python Macro is listed within the LibreOffice File&#8217;s name.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="302" height="311" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02.png" alt="" class="wp-image-849" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02.png 302w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02-291x300.png 291w" sizes="auto, (max-width: 302px) 100vw, 302px" /><figcaption class="wp-element-caption">Python Macro HelloWorld is within the calc document.</figcaption></figure>



<p><br>When you choose to edit the Python Macro, select &#8216;Menu&gt;Edit&#8217; from the &#8216;Python scripts&#8217; window. The edited file&#8217;s path is temporary. It is only used for the time of editing this Python program.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="646" height="182" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03.png" alt="" class="wp-image-850" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03.png 646w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03-300x85.png 300w" sizes="auto, (max-width: 646px) 100vw, 646px" /></figure>



<p>So where is the Python Script saved on your hard drive?<br>As I wrote earlier, it&#8217;s embedded in the LibreOffice File. If you don&#8217;t believe me, here is a trick to find out:<br>If I rename my &#8216;HelloWorld.ods&#8217; in &#8216;HelloWorld.zip&#8217;. I can then unzip it to see the archived compressed files and folders that constitute the LibreOffice file itself(with e.g. Archive Manager on Linux, winzip on Windows, or Archive Utility on Mac). In the list of folders, I spot a folder called &#8216;Scripts&#8217;. Then, I find a sub-folder called &#8216;python&#8217;. OH SURPRISE! The python script is there!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="424" height="355" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04.png" alt="" class="wp-image-851" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04.png 424w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04-300x251.png 300w" sizes="auto, (max-width: 424px) 100vw, 424px" /></figure>



<p> If you want to do that too, when you&#8217;re done don&#8217;t forget to rename the file back with its &#8216;.ods&#8217; extension.</p>



<p>In the second case scenario,we are saving our Python script our Python script &#8216;Testing.py&#8217; is not listed in the Macro manager within the LibreOffice File, but this time I created it as part of my Library &#8216;MyPythonLibrary&#8217; within another Library called &#8216;Tutorial&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="362" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00.png" alt="" class="wp-image-847" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00.png 362w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00-291x300.png 291w" sizes="auto, (max-width: 362px) 100vw, 362px" /><figcaption class="wp-element-caption">&#8216;main&#8217; is the Python function that is in the File &#8216;Testing.py&#8217;.</figcaption></figure>



<p>And this time if I edit &#8216;Testing&#8217;, I can see the path is not a temporary one. I can access it even when LibreOffice is closed.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="685" height="282" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05.png" alt="" class="wp-image-852" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05.png 685w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05-300x124.png 300w" sizes="auto, (max-width: 685px) 100vw, 685px" /></figure>



<p>In fact your Python programs can be directly accessed on your computer at the following location:<br><span style="text-decoration: underline;">For Linux: </span><br>/home/&lt;user name&gt;/.config/libreoffice/4/user/Scripts/python<br>(to see folder &#8216;.config&#8217; you need to &#8216;Show hidden files&#8217; , the shortcut CTRL+h).<br><span style="text-decoration: underline;">For Windows:</span><br>C:\Users\&lt;user_name&gt;\AppData\Roaming\LibreOffice\4\Scripts\python<br><span style="text-decoration: underline;">For Mac:</span><br>(I think it&#8217;s)/Users/&lt;user name&gt;/Library/Application Support/LibreOffice/4/user\Scripts\python<br>(Please let me know in a comment if you know for sure what the folder is for Mac OS).</p>



<h4 class="wp-block-heading">Time for your First LibreOffice line of code!</h4>



<p>I know you can&#8217;t wait anymore! So let&#8217;s create our first program in Python in a LibreOffice Calc Document in <a href="https://tutolibro.org/2025/11/03/write-hello-world-in-libreoffice-calc-using-python/" data-type="post" data-id="1533">this next post</a>.</p>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/11/19/embedding-vs-storing-python-macros-in-libreoffice/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1580</post-id>	</item>
		<item>
		<title>Write &#8216;Hello World!&#8221; in LibreOffice Calc using Python</title>
		<link>https://tutolibro.org/2025/11/03/write-hello-world-in-libreoffice-calc-using-python/</link>
					<comments>https://tutolibro.org/2025/11/03/write-hello-world-in-libreoffice-calc-using-python/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Mon, 03 Nov 2025 23:00:40 +0000</pubDate>
				<category><![CDATA[Calc]]></category>
		<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[libreoffice]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1533</guid>

					<description><![CDATA[First let&#8217;s get the coding done, then we&#8217;ll dive in to it. You can either copy this block of code above or better type it yourself. Typing the code yourself will take longer but it&#8217;s the best way to remember...<br /><a class="read-more-button" href="https://tutolibro.org/2025/11/03/write-hello-world-in-libreoffice-calc-using-python/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p>First let&#8217;s get the coding done, then we&#8217;ll dive in to it.</p>



<pre class="wp-block-code"><code># Created by Gweno 16/08/2019 for tutolibro.org
# This program displays 'Hello World!" in cell A1 of the 
# current Calc document.

# get the doc from the scripting context 
# which is made available to all scripts
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()

def HelloWorld():
    """Write 'Hello World!' in Cell A1"""

    # access the active sheet
    active_sheet = model.CurrentController.ActiveSheet

    # write 'Hello World' in A1
    active_sheet.getCellRangeByName("A1").String = "Hello World!"
</code></pre>



<p>You can either copy this block of code above or better type it yourself. Typing the code yourself will take longer but it&#8217;s the best way to remember a new language.</p>



<p>The first lines starting with &#8216;#&#8217; are comments. <br>A comment in a program is a line that is not processed when the program is executed. It helps the person reading the program to understand what the code is doing. Most of the time, this person is yourself. Comments will help you remember what you were trying to achieve with this code.</p>



<p>The blank space at the start of indented lines should be made of 4 spaces:<br><code>&nbsp;&nbsp;&nbsp;&nbsp;active_sheet = model.CurrentController.ActiveSheet</code></p>



<p>If you don&#8217;t do that it will create an error because the Python interpreter will not recognise the line as being part of the function define by:<br><code>def HelloWorld():</code></p>



<p>The instruction &#8216;def&#8217; is to &#8216;define a function&#8217;. A function is a set of written instructions. It can be run on its own. It can also be &#8216;called&#8217; by other functions to be executed.<br>Our function here is called &#8216;HelloWorld&#8217;. The part between parenthesis &#8216;()&#8217; is where you write the arguments to be used by the function. In our case we are not &#8216;passing&#8217; any argument to the function &#8216;HelloWorld&#8217; for now. That&#8217;s why we have nothing within the parenthesis &#8216;()&#8217;.<br>If you want to assign this macro to a button, you need to pass a specific argument. This argument is necessary for the macro to work when pressing the button. (see <a href="https://tutolibro.org/2025/10/27/libreoffice-calc-python-programming-part-2-hello-world/" data-type="post" data-id="578">this post</a> explains how to assign a button to a python macro)</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="590" height="384" src="https://tutolibro.org/wp-content/uploads/2025/11/HelloWorldCalc.png" alt="" class="wp-image-1540" srcset="https://tutolibro.org/wp-content/uploads/2025/11/HelloWorldCalc.png 590w, https://tutolibro.org/wp-content/uploads/2025/11/HelloWorldCalc-300x195.png 300w" sizes="auto, (max-width: 590px) 100vw, 590px" /></figure>



<p><strong><span style="text-decoration: underline;">Explanations:</span></strong><br><strong>Lines 1,2,3,5,6: </strong>these lines start with a &#8216;#&#8217; so they are comments.<br><strong>Lines 4,9,18:</strong> these empty lines are only for making the program easier to read. They serve to separate the different sets of instructions within the program. The Python interpreter does not need them but these empty lines make the code more readable for us.</p>



<p><strong>Line 7:</strong><br><code>desktop = <a href="https://tutolibro.tech/2022/11/14/what-is-xscriptcontext/" data-type="post" data-id="1149">XSCRIPTCONTEXT</a>.<a type="post" href="https://tutolibro.org/2023/02/08/what-is-getdesktop/" id="1157">getDesktop</a>()</code><br>This line is what allows us to use Python language to manipulate LibreOffice&#8217;s components. It is a bit complicated to explain exactly what this line does. In short, we define &#8216;desktop&#8217; to hold the &#8216;<code><a href="https://tutolibro.tech/2022/11/14/what-is-xscriptcontext/" data-type="post" data-id="1149">XSCRIPTCONTEXT</a></code>&#8216; interface provided by LibreOffice for our scripts (programs). The &#8216;<a type="post" href="https://tutolibro.org/2023/02/08/what-is-getdesktop/" id="1157">getDesktop</a>()&#8217; function is used to obtain a reference for our scripts to operate on. (It is not a reference to a computer desktop!). (Click on the links above to read more in my &#8216;bitesize&#8217; section).</p>



<p><strong>Line 8:</strong><br><code>model = desktop.getCurrentComponent()</code><br>Here, we define &#8216;model&#8217; to be the current component of &#8216;desktop&#8217;. Thus, we are referencing the current document open. It should be a Calc document<strong>.</strong></p>



<p><strong>Line 10:</strong><br><code>def HelloWorld():</code> <br>Define a new function called &#8216;HelloWorld&#8217; that has no arguments.<br>The &#8216;:&#8217; at the end is essential, it&#8217;s to say that what is following is the actual code written for this function. And every line that follow this function&#8217;s 1st line should start with 4 spaces.<br>The function finishes when there is no lines after it. Or when the next non empty line is not a comment and starts with no space.<br><strong>Line 11:</strong><br>      &#8220;&#8221;&#8221;Write &#8216;Hello World!&#8217; in Cell A1&#8243;&#8221;&#8221;<br>This line is simply a description of the function. Also called a Docstring (DocStrings is short for Documentation Strings), it starts and ends with 3 quotation marks. It is not really useful for us right now. Still, it is good practice to have a short description for each of your functions. It&#8217;s different from a comment because this description can be displayed outside of the program as a &#8216;help&#8217; note.<br>To display docstrings, you can use the built-in function &#8216;help&#8217;, like illustrated in the APSO console below:</p>



<p><img loading="lazy" decoding="async" width="450" height="202" class="wp-image-1541" style="width: 450px;" src="https://tutolibro.org/wp-content/uploads/2025/11/help_helloworld.png" alt="Help function to display Docstring of HelloWorld.py" srcset="https://tutolibro.org/wp-content/uploads/2025/11/help_helloworld.png 354w, https://tutolibro.org/wp-content/uploads/2025/11/help_helloworld-300x135.png 300w" sizes="auto, (max-width: 450px) 100vw, 450px" /><br><strong><br>Line 14:</strong><br><code>&nbsp;&nbsp;&nbsp;&nbsp;active_sheet = model.CurrentController.ActiveSheet</code><br>Here we are defining &#8216;active_sheet&#8217; to be the current spreadsheet you are looking at.<br><strong>Line 17:</strong><br><code>&nbsp;&nbsp;&nbsp;&nbsp;active_sheet.getCellRangeByName("A1").String = "Hello World!"</code><br>Finally! Now we have a reference to the current LibreOffice Context. We have the current LibreOffice Calc Document (component) and the current spreadsheet. Therefore, we can access the cell &#8216;A1&#8217;. We can then assign to its &#8216;String&#8217; parameter the text &#8220;Hello World!</p>



<p><strong><span style="text-decoration: underline;">Exercise:</span></strong><br>Add to function HelloWorld a line of code to display &#8220;Bye Bye World!&#8221; in cell &#8216;B2&#8217;. I am sure you can handle that!</p>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/11/03/write-hello-world-in-libreoffice-calc-using-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1533</post-id>	</item>
		<item>
		<title>LibreOffice Calc &#038; Python Programming: Part 2 – Hello World</title>
		<link>https://tutolibro.org/2025/10/27/libreoffice-calc-python-programming-part-2-hello-world/</link>
					<comments>https://tutolibro.org/2025/10/27/libreoffice-calc-python-programming-part-2-hello-world/#comments</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Mon, 27 Oct 2025 00:32:47 +0000</pubDate>
				<category><![CDATA[Calc]]></category>
		<category><![CDATA[LibreOffice]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[calc]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[libreoffice]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">http://superbusydaddy.com/?p=578</guid>

					<description><![CDATA[In this episode of my LibreOffice Calc &#38; Python Programming tutorial, we are going to write our first Python Macro. It will write &#8216;Hello World&#8217; in cell A1 of a LibreOffice Calc document. How exciting is that!?! Here is the...<br /><a class="read-more-button" href="https://tutolibro.org/2025/10/27/libreoffice-calc-python-programming-part-2-hello-world/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p id="top">In this episode of my LibreOffice Calc &amp; Python Programming tutorial, we are going to write our first Python Macro. It will write &#8216;Hello World&#8217; in cell A1 of a LibreOffice Calc document. How exciting is that!?!</p>



<p>Here is the plan for this part 2 of the tutorial:</p>



<ul class="wp-block-list">
<li><a href="#workflow">Get your workflow</a> right: deciding between your macro embedded in the file or saved in a macro repository.</li>



<li><a href="#code">First line of code</a> and writing &#8220;Hello World!&#8221; in Cell A1.</li>



<li id="workflow">Assigning the macro to a LibreOffice <a href="#button">Control Button</a>.</li>
</ul>



<h4 class="wp-block-heading">Get your workflow right                                                                                                                 (<a href="#top">Back to top</a>)</h4>



<p>With the APSO add-on (<a href="https://tutolibro.org/2019/07/26/libreoffice-calc-python-programming-part-1-requirements/">see previous article</a>) you can embed your macro within the LibreOffice File. This can be useful when you want to send your file with the Python Macro. One downside if you do that is that the Python macro is not accessible outside of the LibreOffice file. So you&#8217;ll need to open the LibreOffice file and open the Python Macro organiser in order to edit the Python program. There are alternatives to embedding the Python program. You can place it in an organized directory while still using APSO. This allows you to re-use it for any other LibreOffice document. You can also edit the program without opening the LibreOffice document if you open it from the relevant folder. If you want to send your LibreOffice Document to someone, there is a trade-off. You will also need to send the Python macro.</p>



<p>I am in favor of keeping my programs in a tidy manner. This approach allows me to re-use them across many different files. However, the choice is entirely up to you.</p>



<p>To illustrate these 2 cases, let&#8217;s have a look at an example:</p>



<p>I have a file called &#8220;<strong>HelloWorld.ods</strong>&#8221; and two Python files: the first one is called &#8220;<strong>HelloWorld.py</strong>&#8221; and the other file is called &#8220;<strong>Testing.py&#8221;</strong>. The first python file is embedded in the LibreOffice file, the second is in the shared Python Scripts directory.</p>



<p class="has-text-align-left">In the first case scenario, after opening HelloWorld.ods, I can go to the Python Script Organizer, in Tools&gt;Macro&gt;Organize Python Scripts (shortcut Alt+Shift+F11) from the APSO extension. Alternatively I can use the LibreOffice Standard Macro Organiser in Tools&gt;Macro&gt;Organise Macros&gt;Python&#8230;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="543" height="672" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01.png" alt="" class="wp-image-848" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01.png 543w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc01-242x300.png 242w" sizes="auto, (max-width: 543px) 100vw, 543px" /></figure>



<p class="has-text-align-left"><br>In the Python Scripts Organiser you will see that your Python Macro is listed within the LibreOffice File&#8217;s name.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="302" height="311" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02.png" alt="" class="wp-image-849" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02.png 302w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc02-291x300.png 291w" sizes="auto, (max-width: 302px) 100vw, 302px" /><figcaption class="wp-element-caption">Python Macro HelloWorld is within the calc document.</figcaption></figure>



<p><br>When you choose to edit the Python Macro, select &#8216;Menu&gt;Edit&#8217; from the &#8216;Python scripts&#8217; window. The edited file&#8217;s path is temporary. It is only used for the time of editing this Python program.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="646" height="182" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03.png" alt="" class="wp-image-850" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03.png 646w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc03-300x85.png 300w" sizes="auto, (max-width: 646px) 100vw, 646px" /></figure>



<p>So where is the Python Script saved on your hard drive?<br>As I wrote earlier, it&#8217;s embedded in the LibreOffice File. If you don&#8217;t believe me, here is a trick to find out:<br>If I rename my &#8216;HelloWorld.ods&#8217; in &#8216;HelloWorld.zip&#8217; I can then unzip it to see the archived compressed files and folders that constitute the LibreOffice file itself (with  e.g. Archive Manager on Linux, winzip on Windows, or Archive Utility on Mac). In the list of folders I can then spot a folder called &#8216;Scripts&#8217;, then a sub-folder called &#8216;python&#8217;, and OH SURPRISE! the python script is there!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="424" height="355" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04.png" alt="" class="wp-image-851" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04.png 424w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc04-300x251.png 300w" sizes="auto, (max-width: 424px) 100vw, 424px" /></figure>



<p> If you want to do that too, when you&#8217;re done don&#8217;t forget to rename the file back with its &#8216;.ods&#8217; extension.</p>



<p>In the second case scenario,we are saving our Python script our Python script &#8216;Testing.py&#8217; is not listed in the Macro manager within the LibreOffice File, but this time I created it as part of my Library &#8216;MyPythonLibrary&#8217; within another Library called &#8216;Tutorial&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="362" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00.png" alt="" class="wp-image-847" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00.png 362w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc00-291x300.png 291w" sizes="auto, (max-width: 362px) 100vw, 362px" /><figcaption class="wp-element-caption">&#8216;main&#8217; is the Python function that is in the File &#8216;Testing.py&#8217;.</figcaption></figure>



<p>And this time if I edit &#8216;Testing&#8217;, I can see the path is not a temporary one and I can access it even when LibreOffice is closed.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="685" height="282" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05.png" alt="" class="wp-image-852" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05.png 685w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc05-300x124.png 300w" sizes="auto, (max-width: 685px) 100vw, 685px" /></figure>



<p id="code">In fact your Python programs can be directly accessed on your computer at the following location:<br><span style="text-decoration: underline;">For Linux: </span><br>/home/&lt;user name&gt;/.config/libreoffice/4/user/Scripts/python<br>(to see folder &#8216;.config&#8217; you need to &#8216;Show hidden files&#8217; , the shortcut CTRL+h).<br><span style="text-decoration: underline;">For Windows:</span><br>C:\Users\&lt;user_name&gt;\AppData\Roaming\LibreOffice\4\Scripts\python<br><span style="text-decoration: underline;">For Mac:</span><br>(I think it&#8217;s)/Users/&lt;user name&gt;/Library/Application Support/LibreOffice/4/user\Scripts\python<br>(Please let me know in a comment if you know for sure what the folder is for Mac OS).</p>



<h4 class="wp-block-heading">First line of code!                                                                                                                 (<a href="#top">Back to top</a>)</h4>



<p>I know you can&#8217;t wait anymore! So let&#8217;s write our first line of code in Python, within a LibreOffice Calc Document.</p>



<p>So after creating a new Calc document, go in the Macro manager (if you have installed the APSO extension: ALT+Shift+F11), then as explained earlier in this lesson you can have your program either in calc document or in a library outside the document. To do so, choose between &#8216;My Macros&#8217;, &#8216;LibreOffice Macros&#8217; or the name of the document itself.<br>I do prefer saving my python macros in the &#8216;My Macros&#8217; Library.<br>You can also create sub-folders, called  libraries, or directly create your program by choosing &#8216;Create Module&#8217; in the &#8216;Menu&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="339" height="335" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc06.png" alt="" class="wp-image-853" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc06.png 339w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc06-300x296.png 300w" sizes="auto, (max-width: 339px) 100vw, 339px" /></figure>



<p>So go ahead and create a Module, name it &#8220;HelloWorld&#8221;, then once the module is listed and selected, click again on &#8216;Menu&#8217; and choose &#8216;edit&#8217;.</p>



<p>And then you get either a default editor or the one you have linked with APSO to pop up with a new program that content nothing but a couple of lines like these:</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="427" height="76" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc07.png" alt="" class="wp-image-854" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc07.png 427w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc07-300x53.png 300w" sizes="auto, (max-width: 427px) 100vw, 427px" /></figure>



<p>The first line is a comment.<br>A comment in a program is a line that is not processed when the program is executed. So it&#8217;s not a line of code, it is usually to help the person who is going to read your program (most of the time, yourself) to understand what the following code is aiming to do.<br>So to write comments in your Python programs simply add a &#8216;#&#8217; at the start of the line.<br>Don&#8217;t worry about the second line, in fact you can delete these two lines for now.<br>Instead you could like me write your name, the date and what the program is for:</p>



<p><code># Created by Gweno 16/08/2019 for tutolibro.tech<br># This program displays 'Hello World!" in cell A1 of the</code><br><code># current Calc document.</code></p>



<p>Then Finally here is the code for writing &#8220;Hello World!&#8221; in cell A1:</p>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="wp-block-code"><code># Created by Gweno 16/08/2019 for tutolibro.tech
# This program displays 'Hello World!" in cell A1 of the 
# current Calc document.

def HelloWorld():
    """Write 'Hello World!' in Cell A1"""

# get the doc from the scripting context
# which is made available to all scripts
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent()

# access the active sheet
    active_sheet = model.CurrentController.ActiveSheet

# write 'Hello World' in A1
    active_sheet.getCellRangeByName("A1").String = "Hello World!"
</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<p>You can either copy this block of code above or better type it manually yourself. Typing the code yourself will take longer but it&#8217;s the best way to remember a new language.<br>When you type it make sure that you leave 4 empty spaces to indent the lines that are not starting at the beginning of their lines, like:<br><code>    desktop = XSCRIPTCONTEXT.getDesktop()</code><br>If you don&#8217;t do that it will create an error because the Python interpreter will not recognise the line as part of the function define by:<br><code>def HelloWorld():</code><br>So the instruction &#8216;def&#8217; is to &#8216;define a function&#8217;. A function is a set of written instructions that can be run on its own or &#8216;called&#8217; by other functions to be executed.<br>Our function here is called &#8216;HelloWorld&#8217; and the part between parenthesis &#8216;()&#8217; is where you write the arguments to be used by the function. In our case we are not &#8216;passing&#8217; any argument to the function &#8216;HelloWorld&#8217; for now, that is why we have nothing within the parenthesis &#8216;()&#8217;.<br>You need to know that when we will assign our macro to a button we will need to pass a specific argument for our macro to work when we press the button.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="605" height="332" src="https://tutolibro.org/wp-content/uploads/2023/11/lopy-helloworld.png" alt="" class="wp-image-1202" srcset="https://tutolibro.org/wp-content/uploads/2023/11/lopy-helloworld.png 605w, https://tutolibro.org/wp-content/uploads/2023/11/lopy-helloworld-300x165.png 300w" sizes="auto, (max-width: 605px) 100vw, 605px" /></figure>



<p><strong><span style="text-decoration: underline;">Explanations:</span></strong><br><strong>Lines 1,2,3,8,9,13,16: </strong>these lines start with a &#8216;#&#8217; so they are comments.<br><strong>Lines 4,7,12,15,18:</strong> these empty lines are only for making the program easier to read,by separating the different set of instructions within the program. The Python interpreter does not need them but these empty lines make the code more readable for us.<br><strong>Line 5:</strong><br><code>def HelloWorld():</code> <br>Define a new function called &#8216;HelloWorld&#8217; that has no arguments.<br>The &#8216;:&#8217; at the end is essential, it&#8217;s to say that what is following is the actual code written for this function. And every line that follow this function&#8217;s 1st line should start with 4 spaces.<br>The function finishes when either there is nothing after, or when a new line starts from the beginning with no space to start with (excluding comment lines).<br><strong>Line 6:</strong><br><code>   """Write 'Hello World!' in Cell A1"""</code><br>This line is simply a description of the function, it starts and ends with 3 quotation marks. It is not really useful for us right now but it is a good practice to have a short description for each of your function. It&#8217;s different from a comment because this description can be displayed from outside of the program as a &#8216;help&#8217; note.<br><strong>Line 10:</strong><br><code>    desktop = <a href="https://tutolibro.tech/2022/11/14/what-is-xscriptcontext/" data-type="post" data-id="1149">XSCRIPTCONTEXT</a>.<a href="https://tutolibro.org/2023/02/08/what-is-getdesktop/" type="post" id="1157">getDesktop</a>()</code><br>This line is what allows us to use Python language to manipulate LibreOffice&#8217;s components. It is a bit complicated to explained exactly what this line does but in short:<br>We define &#8216;desktop&#8217; to hold the &#8216;<code><a href="https://tutolibro.tech/2022/11/14/what-is-xscriptcontext/" data-type="post" data-id="1149">XSCRIPTCONTEXT</a></code>&#8216; interface provided by LibreOffice for our scripts (programs). The &#8216;<a href="https://tutolibro.org/2023/02/08/what-is-getdesktop/" type="post" id="1157">getDesktop</a>()&#8217; function is used to obtain a reference for our scripts to operate on. (It is not a reference to a computer desktop!). (Click on the links above to read more in my &#8216;bitesize&#8217; section)<br><strong>Line 11:</strong><br><code>    model = desktop.getCurrentComponent()</code><br>In the same way we define here &#8216;model&#8217; to be the current component of &#8216;desktop&#8217;, so effectively we are referencing to the current document open, which should be a Calc document<strong>.<br>Line 14:</strong><br><code>    active_sheet = model.CurrentController.ActiveSheet</code><br>Here we are defining &#8216;active_sheet&#8217;  to be the current spreadsheet you are looking at.<br><strong>Line 17:</strong><br><code>    active_sheet.getCellRangeByName("A1").String = "Hello World!"</code><br>Finally! Now that we have a reference to the current LibreOffice Context, the current LibreOffice Calc Document (component) and the current spreadsheet, we can access the cell &#8216;A1&#8217; from that current spreadsheet and assign to its &#8216;String&#8217; parameter the text &#8220;Hello World!&#8221;.</p>



<p id="button"><strong><span style="text-decoration: underline;">Exercise:</span></strong><br>Add to function HelloWorld a line of code to display &#8220;Bye Bye World!&#8221; in cell &#8216;B2&#8217;. I am sure you can handle that!</p>



<h4 class="wp-block-heading">Assign the macro to a LibreOffice Control Button.                                                                    (<a href="#top">Back to top</a>)</h4>



<p>You will quickly realise when you write a macro within libreOffice that it&#8217;s not really convenient to execute them through the Macro Manager because you need to access that menu and it takes a few clicks to do so (Quickest way to access the APSO Macro manager being [Alt] + [Shift] + [F11]). It is easy to create a button on your spreadsheet and to assign it to your macro and then when you&#8217;ll click on that button it will execute the macro.<br>So first we&#8217;ll <strong>create a button</strong> on the spreadsheet then we&#8217;ll <strong>assign the python macro</strong> to this button.</p>



<p><strong><span style="text-decoration: underline;">Create a button</span></strong>:<br>Simply by clicking on Menu &#8216;<strong>Insert&gt;Form Controls&gt;Push Button&#8217;</strong>:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="430" height="711" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc10.png" alt="" class="wp-image-857" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc10.png 430w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc10-181x300.png 181w" sizes="auto, (max-width: 430px) 100vw, 430px" /></figure>



<p>Then once you have the little cross to insert the button, just click for upper left corner of the button, then hold and release where you want the bottom right corner of the button.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="124" height="84" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc11.png" alt="" class="wp-image-858"/></figure>



<p><strong><span style="text-decoration: underline;">Assign the python macro</span></strong><span style="text-decoration: underline;">:</span><br>Once you have the button displayed, right click on it and select &#8216;Control&#8230;&#8217;</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="241" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12.png" alt="" class="wp-image-859" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12.png 241w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc12-194x300.png 194w" sizes="auto, (max-width: 241px) 100vw, 241px" /><figcaption class="wp-element-caption">Select &#8216;Control&#8217; from the new Button contextual menu</figcaption></figure>



<p>Then in the window &#8216;Properties&#8217; select the &#8216;Events&#8217; tab, scroll down a bit to find in the list of events the one called &#8216;Mouse button pressed&#8217;. On the right of this &#8216;Mouse button pressed&#8217; entry click on the button &#8216;[&#8230;]&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="564" height="430" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13.png" alt="" class="wp-image-860" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13.png 564w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc13-300x229.png 300w" sizes="auto, (max-width: 564px) 100vw, 564px" /></figure>



<p>A window named  &#8220;Assign Action&#8217; pops up, click on the button &#8216;[Macro]&#8217; on the right hand side of this window.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="592" height="373" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14.png" alt="" class="wp-image-861" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14.png 592w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc14-300x189.png 300w" sizes="auto, (max-width: 592px) 100vw, 592px" /><figcaption class="wp-element-caption">Assign a macro to a button</figcaption></figure>



<p>You should then get the &#8216;Macro Selector&#8217; with your Macro Libraries. Simply go to the library where your macro is saved and select the macro &#8216;HelloWorld&#8217;,then press &#8216;OK&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="722" height="202" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973.png" alt="" class="wp-image-862" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973.png 722w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc15-e1565986476973-300x84.png 300w" sizes="auto, (max-width: 722px) 100vw, 722px" /><figcaption class="wp-element-caption">Select the macro from Macro Selector</figcaption></figure>



<p>Then &#8216;OK&#8217; again in &#8216;Assign Macro&#8217; window, than close the &#8216;Properties&#8217; window.<br>Last thing to do is to come out the &#8216;Design&#8217; mode to be able to click on the button, do that by going to &#8216;Tools&gt;Forms&gt;Design Mode&#8217;.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="461" height="541" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17.png" alt="" class="wp-image-864" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17.png 461w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc17-256x300.png 256w" sizes="auto, (max-width: 461px) 100vw, 461px" /><figcaption class="wp-element-caption">Set design mode off</figcaption></figure>



<p>And now when you click on the button&#8230; tada&#8230;<br>ERROR!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="546" height="255" src="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16.png" alt="" class="wp-image-863" srcset="https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16.png 546w, https://tutolibro.org/wp-content/uploads/2019/08/pyCalc16-300x140.png 300w" sizes="auto, (max-width: 546px) 100vw, 546px" /><figcaption class="wp-element-caption">Error: missing argument</figcaption></figure>



<p>This is because to be able to work, the function HelloWorld need all information from LibreOffice Context in the form of an argument. So we need to pass the argument &#8216;*args&#8217; in our function HelloWorld. So in your code in line 5 instead of:<br><code>def HelloWorld():</code><br>You should have:<br><code>def HelloWorld(*args):</code><br>Save your program again and then when you press on the button the cell  A1 will display &#8216;Hello World!&#8217; !!!</p>



<p>So there is the final version of the macro:</p>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="wp-block-code"><code># Created by Gweno 16/08/2019 for tutolibro.tech
# This program displays 'Hello World!" in cell A1 of the 
# current Calc document.

def HelloWorld(*args):
    """Write 'Hello World!' in Cell A1"""
    
# get the doc from the scripting context 
# which is made available to all scripts
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent()
    
# access the active sheet
    active_sheet = model.CurrentController.ActiveSheet

# write 'Hello World' in A1
    active_sheet.getCellRangeByName("A1").String = "Hello World!"</code></pre>



<p>You can clone or download this code from gitHub <a href="https://github.com/Gweno/tutolibro.tech/tree/master/lopy/part2">here</a>.</p>



<hr class="wp-block-separator has-css-opacity"/>



<h3 class="wp-block-heading">Good luck! and leave a comment if you are having problem to have this macro to work.</h3>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-default"/>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/10/27/libreoffice-calc-python-programming-part-2-hello-world/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">578</post-id>	</item>
		<item>
		<title>Create Documents from Templates Using Python in LibreOffice</title>
		<link>https://tutolibro.org/2025/10/24/libreoffice-document-from-template-with-python/</link>
					<comments>https://tutolibro.org/2025/10/24/libreoffice-document-from-template-with-python/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Fri, 24 Oct 2025 15:33:58 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1515</guid>

					<description><![CDATA[Let&#8217;s start with the full code, then dive down First we need to import the uno library and the specific PropertyValue function Then let&#8217;s set the couple of service definitions that we need: We create 3 functions: create_instance: new_document_from_template: This...<br /><a class="read-more-button" href="https://tutolibro.org/2025/10/24/libreoffice-document-from-template-with-python/">Read more</a>]]></description>
										<content:encoded><![CDATA[
<p>Let&#8217;s start with the full code, then dive down</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code># Created by Gweno 24/10/2025
# For tutolibro.org
# Public Domain, feel free to copy, modify, use in your own scripts
# 
# email: gweno@tutolibro.org

# This needs to be run from any instance of LibreOffice already open

# Python modules to import for this script:
import uno
from com.sun.star.beans import PropertyValue

# UNO service definition for creating document
context = uno.getComponentContext()
service_manager = context.getServiceManager()
    
def create_instance(name, with_context=False):
    if with_context:
        instance = service_manager.createInstanceWithContext(name, context)
    else:
        instance = service_manager.createInstance(name)
    return instance

def new_document_from_template(*args):
    desktop = create_instance('com.sun.star.frame.Desktop', True)
    properties = (PropertyValue(Name='AsTemplate', Value=True),)
    # full path to template here
    path = 'file:///usr/lib/libreoffice/share/template/common/officorr/Modern_business_letter_serif.ott'
    doc = desktop.loadComponentFromURL(path, '_default', 0, properties)
    return doc

def main():
    """ Creates a new document from a LibreOffice Temple (*.ott)"""
    
    new_document_from_template()
    
    
if __name__ == "__main__":
    main()
</code></pre>



<p><br>First we need to import the uno library and the specific PropertyValue function</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code># Python modules to import for this script:
<code>import uno
from com.sun.star.beans import PropertyValue</code></code></pre>



<p>Then let&#8217;s set the couple of service definitions that we need:</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code># UNO service definition for creating document
context = uno.getComponentContext()
service_manager = context.getServiceManager()</code></pre>



<p>We create 3 functions:</p>



<p><strong>create_instance</strong>:</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code>def create_instance(name, with_context=False):
    if with_context:
        instance = service_manager.createInstanceWithContext(name, context)
    else:
        instance = service_manager.createInstance(name)
    return instance</code></pre>



<p><strong>new_document_from_template</strong>:</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code>def new_document_from_template(*args):
    desktop = create_instance('com.sun.star.frame.Desktop', True)
    properties = (PropertyValue(Name='AsTemplate', Value=True),)
    # full path to template here
    path = 'file:///usr/lib/libreoffice/share/template/common/officorr/Modern_business_letter_serif.ott'
    doc = desktop.loadComponentFromURL(path, '_default', 0, properties)
    return doc</code></pre>



<p>This function creates the new document itself from an template example within the shared library of LibreOffice. <br>Note the hard coded path, starting with &#8216;file://&#8217; followed by the actual path for the file.<br>You can use your own template file. It doesn&#8217;t need to be a file with a &#8216;. ott&#8217; extension. You can also us a or a regular &#8216;.odt&#8217; file.<br>The example below shows the path for a simple odt file in my Templates folder. The new document will be new untitled file, copy of &#8216;MyDocs.odt&#8217;.</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code>path = 'file:///home/gweno/Templates/MyDoc.odt'</code></pre>



<p>I do recommend to use a dedicated template file wit &#8216;.ott&#8217; for clarity and to be able to use it with the build-in LibreOffice Template management along with Templates features.</p>



<p>Finally, the <strong>main</strong> function just calls new_document_from_template:</p>



<pre class="wp-block-code has-cyan-bluish-gray-background-color has-background"><code>def main():
    """ Creates a new document from a LibreOffice Temple (*.ott)"""
    
    new_document_from_template()</code></pre>



<p>To execute.</p>



<p>Save the full code in a file in your usual python library for LibreOffice scripts to be able to execute this script from any open instance of LibreOffice.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/10/24/libreoffice-document-from-template-with-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1515</post-id>	</item>
		<item>
		<title>Runner Bean Race 2025</title>
		<link>https://tutolibro.org/2025/10/24/runner-bean-race-2025/</link>
					<comments>https://tutolibro.org/2025/10/24/runner-bean-race-2025/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Fri, 24 Oct 2025 10:26:29 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[runner beans race]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1511</guid>

					<description><![CDATA[Watch year 2025 edition of The World Famous &#8216;Runner Beans Race&#8217;. Racers on the starting line:]]></description>
										<content:encoded><![CDATA[
<p>Watch year 2025 edition of The World Famous &#8216;Runner Beans Race&#8217;.</p>



<span id="more-1511"></span>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Runner Beans Race 2025" width="734" height="413" src="https://www.youtube.com/embed/dY35583vgvk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>Racers on the starting line:</p>



<ol class="wp-block-list">
<li>Ronalbeano</li>



<li>Harry Cover</li>



<li>Brian</li>



<li>Milkman</li>



<li>War Pig</li>



<li>Insert your Name here</li>



<li>Jas Favola</li>



<li>Melodeon</li>



<li>Beans are Cool!</li>



<li>Wind Breaker</li>



<li>J Bean</li>



<li>Your Bean</li>
</ol>



<details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary>Podium for the 2025 edition of the Runner Beans Race (click to reveal)</summary>
<p>Gold: Wind Breaker<br>Silver: Brian<br>Bronze: Melodeon<br>Runner up: Jas Favola<br>5th J Bean<br>6th Insert your name here<br>7th Beans are Cool!<br>8th Ronalbeano<br>9th Harry Cover<br>10th War Pig<br>11 Milkman<br>12 Your Bean (non starter)</p>
</details>



<p></p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/10/24/runner-bean-race-2025/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1511</post-id>	</item>
		<item>
		<title>Runner Bean Race 2024</title>
		<link>https://tutolibro.org/2025/04/28/runner-bean-race-2024/</link>
					<comments>https://tutolibro.org/2025/04/28/runner-bean-race-2024/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Mon, 28 Apr 2025 20:11:15 +0000</pubDate>
				<category><![CDATA[Misc]]></category>
		<guid isPermaLink="false">https://tutolibro.org/?p=1494</guid>

					<description><![CDATA[Watch year 2024 edition of The World Famous &#8216;Runner Beans Race&#8217;. Racers on the starting line: Podium for the 2024 edition of the Runner Beans Race: Gold: ValbeanSilver: Mr BeanBronze: Bean Bappé]]></description>
										<content:encoded><![CDATA[
<p>Watch year 2024 edition of The World Famous &#8216;Runner Beans Race&#8217;.</p>



<span id="more-1494"></span>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Runner Beans Race 2024!" width="734" height="551" src="https://www.youtube.com/embed/vGAA7gJznhE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>Racers on the starting line:</p>



<ol class="wp-block-list">
<li> Bean Bappé</li>



<li>Jack &amp; the &#8230;</li>



<li>It&#8217;s Fun to grow a B.E.A.N</li>



<li>Mr Bean</li>



<li>Bean Where?</li>



<li>Jack&#8217;O Bean</li>



<li>Kyle Bean</li>



<li>Valbean</li>



<li>Bean Breaker</li>
</ol>



<p>Podium for the 2024 edition of the Runner Beans Race:</p>



<p>Gold:  Valbean<br>Silver: Mr Bean<br>Bronze: Bean Bappé</p>



<details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary>Podium for the 2024 edition of the Runner Beans Race (click to reveal)</summary>
<p>Gold: Valbean<br>Silver: Mr Bean<br>Bronze: Bean Bappé</p>
</details>



<p></p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2025/04/28/runner-bean-race-2024/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1494</post-id>	</item>
		<item>
		<title>What is getDesktop () ?</title>
		<link>https://tutolibro.org/2023/02/08/what-is-getdesktop/</link>
					<comments>https://tutolibro.org/2023/02/08/what-is-getdesktop/#respond</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Wed, 08 Feb 2023 11:12:28 +0000</pubDate>
				<category><![CDATA[Bitesize]]></category>
		<guid isPermaLink="false">https://tutolibro.tech/?p=1157</guid>

					<description><![CDATA[Usually the first statement, when scripting with python to work on a LibreOffice document, would be:desktop = XSCRIPTCONTEXT.getDesktop() getDesktop() is a method of the object XSCRIPTCONTEXT and returns the Desktop Reference on which our script can interact with. This reference...<br /><a class="read-more-button" href="https://tutolibro.org/2023/02/08/what-is-getdesktop/">Read more</a>]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image is-resized">
<figure class="aligncenter size-thumbnail"><img loading="lazy" decoding="async" width="150" height="150" src="https://tutolibro.org/wp-content/uploads/2023/02/logo-bitesize_alpha-150x150.png" alt="" class="wp-image-1167"/></figure></div>


<p>Usually the first statement, when scripting with python to work on a LibreOffice document, would be:<br><code>desktop = <a href="https://tutolibro.org/2022/11/14/what-is-xscriptcontext/" type="post" id="1149">XSCRIPTCONTEXT</a>.<strong>getDesktop()</strong></code></p>



<p>getDesktop() is a method of the object <a href="https://tutolibro.org/2022/11/14/what-is-xscriptcontext/" type="post" id="1149">XSCRIPTCONTEXT</a> and returns the Desktop Reference on which our script can interact with. This reference is the main interface of the Desktop Service.</p>



<p>It allows to access useful methods from the Desktop interface like <code>getCurrentComponent()</code> or <code>getComponents()</code>. The &#8216;current Component&#8217; being the active document on which you will be able to work directly, for example editing text or cells.</p>



<h2 class="wp-block-heading">Still hungry?</h2>



<p>The getDesktop() method is a method of class ScriptContext and is define in pythonscript.py. You can find pythonscript.py in <code>/lib/libreoffice/program</code> on Linux, probably in a similar path on MacOs and in C:\Program Files\LibreOffice\program on Windows (standard install).</p>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2023/02/08/what-is-getdesktop/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1157</post-id>	</item>
		<item>
		<title>What is XSCRIPTCONTEXT ?</title>
		<link>https://tutolibro.org/2022/11/14/what-is-xscriptcontext/</link>
					<comments>https://tutolibro.org/2022/11/14/what-is-xscriptcontext/#comments</comments>
		
		<dc:creator><![CDATA[gweno]]></dc:creator>
		<pubDate>Mon, 14 Nov 2022 12:28:19 +0000</pubDate>
				<category><![CDATA[Bitesize]]></category>
		<guid isPermaLink="false">https://tutolibro.tech/?p=1149</guid>

					<description><![CDATA[When you program a script within LibreOffice, accessing the XSCRIPTCONTEXT object is the starting point for controlling LibreOffice documents. SCRIPTCONTEXT is an object of class &#8216;pythonscript.ScriptContext&#8217;.This object provides connections with running instances of LibreOffice and has four useful methods:getDocument ()getInvocationContext...<br /><a class="read-more-button" href="https://tutolibro.org/2022/11/14/what-is-xscriptcontext/">Read more</a>]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image is-resized">
<figure class="aligncenter size-thumbnail"><img loading="lazy" decoding="async" width="150" height="150" src="https://tutolibro.org/wp-content/uploads/2023/02/logo-bitesize_alpha-150x150.png" alt="" class="wp-image-1167"/></figure></div>


<p>When you program a script within LibreOffice, accessing the XSCRIPTCONTEXT object is the starting point for controlling LibreOffice documents.</p>



<p>SCRIPTCONTEXT is an object of class &#8216;pythonscript.ScriptContext&#8217;.<br>This object provides connections with running instances of LibreOffice and has four useful methods:<br>getDocument ()<br>getInvocationContext ()<br><a href="https://tutolibro.org/2023/02/08/what-is-getdesktop/" type="post" id="1157">getDesktop ()</a><br>getComponentContext ()</p>



<h2 class="wp-block-heading">Still hungry?</h2>



<p> Here pythonscript is the python program that defines the context for Python scripts in . You can find pythonscript.py in /lib/libreoffice/program on Linux, probably in a similar path on MacOs and in C:\Program Files\LibreOffice\program on Windows (standard install).<br>ScriptContext is a Class inherited from unohelper.base and defined in pythonscript.py.<br>On linux Mint, unohelper.py is in /lib/python3/dist-packages and MacOS (most likely), and in  C:\Program Files\LibreOffice\program on Windows (standard install).<br>The unohelper.Base itself is a class inherited from XTypeProvider, the latest being imported from com.sun.star.lang and being inherited from XInterface.</p>



<p>If you like this tutorial, you could <a href="https://buymeacoffee.com/tutolibro" data-type="link" data-id="https://buymeacoffee/tutolibro" target="_blank" rel="noreferrer noopener">buy me a coffee</a> to help me continue writing add-free tutorials.</p>



<p>Thank you!</p>



<div class="wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex">

</div>
]]></content:encoded>
					
					<wfw:commentRss>https://tutolibro.org/2022/11/14/what-is-xscriptcontext/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1149</post-id>	</item>
	</channel>
</rss>
