Skip to content

Commit

Permalink
Version 5
Browse files Browse the repository at this point in the history
  • Loading branch information
goosepirate committed Sep 11, 2023
1 parent 58c6361 commit 781f88f
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 10 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Similar to Excel's [FILTER](https://support.microsoft.com/en-us/office/filter-fu
* `include`: An array of booleans where TRUE represents a row or column to retain.
* `[if_empty]`: Returned if no items are retained. Optional.

#### IMAGE

Returns an image from a given source.

The source can be a local image file or a web URL. You can use a web URL of a third-party service to generate, for example, a QR code, equation, or diagram.

Similar to Excel's [IMAGE](https://support.microsoft.com/en-us/office/image-function-7e112975-5e52-4f2a-b9da-1d913d51f5d5).

![Screenshot of IMAGE function](image7.png)

![Screenshot of IMAGE function](image8.png)

![Screenshot of IMAGE function](image9.png)

![Screenshot of IMAGE function](image10.png)

`=IMAGE(out_cell, source)`
* `out_cell`: Reference to the cell where the image is to be placed.
* `source`: The path of the source that points to the image.

#### SORT

Sorts an array.
Expand Down
15 changes: 15 additions & 0 deletions addin.xcu
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
</node>
</node>
</node>
<node oor:name="IMAGE" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">IMAGE</value></prop>
<prop oor:name="Description"><value xml:lang="en">Returns an image from a given source. Provided by Lox365.</value></prop>
<prop oor:name="Category"><value>Add-in</value></prop>
<node oor:name="Parameters">
<node oor:name="out_cell" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">Location</value></prop>
<prop oor:name="Description"><value xml:lang="en">Reference to the cell where the image is to be placed.</value></prop>
</node>
<node oor:name="url" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">Source</value></prop>
<prop oor:name="Description"><value xml:lang="en">The path of the source that points to the image.</value></prop>
</node>
</node>
</node>
<node oor:name="SORT" oor:op="replace">
<prop oor:name="DisplayName"><value xml:lang="en">SORT</value></prop>
<prop oor:name="Description"><value xml:lang="en">Sorts an array. Provided by Lox365.</value></prop>
Expand Down
20 changes: 10 additions & 10 deletions description.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006"
xmlns:dep="http://openoffice.org/extensions/description/2006"
xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="com.goosepirate.lox365.oxt" />
<icon><default xlink:href="icon.png" /></icon>
<version value="4.3" />
<publisher><name xlink:href="https://github.com/goosepirate/lox365" lang="en">goosepirate</name></publisher>
<display-name><name lang="en">Lox365</name></display-name>
<extension-description><src xlink:href="extension-description.txt" lang="en"/></extension-description>
<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006"
xmlns:dep="http://openoffice.org/extensions/description/2006"
xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="com.goosepirate.lox365.oxt" />
<icon><default xlink:href="icon.png" /></icon>
<version value="5.0" />
<publisher><name xlink:href="https://github.com/goosepirate/lox365" lang="en">goosepirate</name></publisher>
<display-name><name lang="en">Lox365</name></display-name>
<extension-description><src xlink:href="extension-description.txt" lang="en"/></extension-description>
</description>
Binary file added image10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions interface.idl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <com/sun/star/beans/XPropertySet.idl>
#include <com/sun/star/table/XCellRange.idl>
#include <com/sun/star/uno/XInterface.idl>

Expand All @@ -8,6 +9,11 @@ module org { module openoffice { module sheet { module addin {
[in] sequence< sequence< any > > include,
[in] any ifEmpty
);
any IMAGE(
[in] com::sun::star::beans::XPropertySet doc,
[in] com::sun::star::table::XCellRange out_cell,
[in] string url
);
sequence< sequence< any > > SORT(
[in] sequence< sequence< any > > array,
[in] any sortIndex,
Expand Down
1 change: 1 addition & 0 deletions loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _get_shrunk_corners(self, cellrange) -> dict:
return useful_positions

def FILTER (self, *args): return lx.FILTER (*args)
def IMAGE (self, *args): return lx.IMAGE (*args)
def SORT (self, *args): return lx.SORT (*args)
def TEXTSPLIT(self, *args): return lx.TEXTSPLIT(*args)
def TOCOL (self, *args): return lx.TOCOL (*args)
Expand Down
45 changes: 45 additions & 0 deletions pythonpath/imagefn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from com.sun.star.awt import Size

def IMAGE(doc, out_cell, url):
drawpages = doc.DrawPages[int(out_cell.RangeAddress.Sheet)]
existing_images = []

def get_existing_images_at_position():
for item in drawpages:
if out_cell.Position != item.Position: continue
existing_images.append(item)
def remove_existing_images_at_position():
[item.dispose() for item in existing_images]

get_existing_images_at_position()

# Parse URL.
if url == '':
remove_existing_images_at_position()
return ''
elif (
not url.startswith('file://')
and not url.startswith('http://')
and not url.startswith('https://')
): # Assume relative file path.
current_dir = doc.URL.split('/')[:-1]
url = '/'.join(current_dir) + '/' + url

image = doc.createInstance('com.sun.star.drawing.GraphicObjectShape')
image.Position = out_cell.Position
image.GraphicURL = url
image.Name = f'Generated image'
try:
drawpages.add(image)
except:
image.dispose()
return ''
size = Size()
multiplier = 2540 * 15 / 1440
size.Width, size.Height = (
image.Graphic.Size.Width * multiplier,
image.Graphic.Size.Height * multiplier,
)
image.setSize(size)
remove_existing_images_at_position()
return ''
5 changes: 5 additions & 0 deletions pythonpath/lox365.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def FILTER(array, include, ifEmpty=ERR_CALC):
ans = tuple(tuple(itertools.compress(row, include[0])) for row in array)
return ans if ans else ((ifEmpty,),)

try:
import imagefn
IMAGE = imagefn.IMAGE
except ImportError: pass

def SORT(array, sortIndex=1, sortOrder=1):
if sortIndex is None: sortIndex = 1
if sortOrder is None or sortOrder == 1: reverse = False
Expand Down

0 comments on commit 781f88f

Please sign in to comment.