Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert a specific range of cells of a Spreadsheet (XLSX) to image (PNG) #613

Open
mmaronbr opened this issue Mar 27, 2024 · 0 comments
Open

Comments

@mmaronbr
Copy link

mmaronbr commented Mar 27, 2024

Greetings!

I'm trying to convert a specific range of cells of an Excel Spreedsheet (XLSX) into a image (PNG).
See example attached: input_file.xlsx

My first attempt was trying to use unoserver/unoconvert (running it via unoserver-docker). But I couldn't find a way to pass via parameters which sheet and range I would like to convert it. I've noticed that unoconvert uses the selected printed area (if it exists) to convert the result into an image. The first sheet is always selected.

So I've installed the unoconv via wget into the container of the unoserver. The idea was to use the "-e" parameter to select both sheet and range like the example below:

$ unoconv -f png -e Sheet=Sheet2 -e Select=A1:F19 -o ./output.png ./input_file.xlsx

First I run the version 0.8.2 of unoconv but the results were the same of unoconvert. Than I tried to run the version 0.9.0 and I got an error.
Using the -vvv parameter I could understand the reason of the error but didn't understand why it changed the office filter from writer_png_Export to draw_png_Export.

Let me show the results:

VERSIONS

https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv

$ unoconv_0.8.2 --version
unoconv 0.8.2
Written by Dag Wieers <dag@wieers.com>
Homepage at http://dag.wieers.com/home-made/unoconv/

platform posix/linux
python 3.11.8 (main, Feb 19 2024, 17:01:17) [GCC 13.2.1 20231014]
LibreOffice 7.6.3.1

https://raw.githubusercontent.com/dagwieers/unoconv/0.9.0/unoconv

$ unoconv_0.9.0 --version
unoconv 0.9.0
Written by Dag Wieers <dag@wieers.com>
Homepage at http://dag.wieers.com/home-made/unoconv/

platform posix/linux
python 3.11.8 (main, Feb 19 2024, 17:01:17) [GCC 13.2.1 20231014]
LibreOffice 7.6.3.1

output:
output_0 8 2

CONVERSIONS

$ unoconv_0.8.2 -f png -vvv -e Sheet=Sheet2 -e Select=A1:F19 -o ./output.png ./input_file.xlsx
Verbosity set to level 3
Using office base path: /usr/lib/libreoffice
Using office binary path: /usr/lib/libreoffice/program
DEBUG: Connection type: socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext
Input file: ./input_file.xlsx
Selected output format: Portable Network Graphic [.png]
Selected office filter: writer_png_Export
Used doctype: document
Output file: file:///data/output.png
$ unoconv_0.9.0 -f png -vvv -e Sheet=Sheet2 -e Select=A1:F19 -o ./output.png ./input_file.xlsx
Verbosity set to level 3
Using office base path: /usr/lib/libreoffice
Using office binary path: /usr/lib/libreoffice/program
DEBUG: Connection type: socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext
Input file: ./input_file.xlsx
Selected output format: Portable Network Graphic [.png]
Selected office filter: draw_png_Export
Used doctype: graphics
Output file: file:///data/output.png
unoconv: UnoException during export phase:
Unable to store document to file:///data/output.png (Error (com.sun.star.io.IOException){ (com.sun.star.uno.Exception){ Message = (string)"SfxBaseModel::impl_store <file:///data/output.png> failed: 0xc10(Error Area:Io Class:Write Code:16) at /home/buildozer/aports/community/libreoffice/src/libreoffice-7.6.3.1/sfx2/source/doc/sfxbasemodel.cxx:3221 at /home/buildozer/aports/community/libreoffice/src/libreoffice-7.6.3.1/sfx2/source/doc/sfxbasemodel.cxx:1792", Context = (com.sun.star.uno.XInterface)0x0{} } })

Properties: ((com.sun.star.beans.PropertyValue){ Name = (string)"FilterName", Handle = (long)0x0, Value = (any){ (string)"draw_png_Export" }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE }, (com.sun.star.beans.PropertyValue){ Name = (string)"OutputStream", Handle = (long)0x0, Value = (any){ (com.sun.star.uno.XInterface)0x7fdf19416e98{, supportedInterfaces={com.sun.star.io.XOutputStream,com.sun.star.lang.XTypeProvider}} }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE }, (com.sun.star.beans.PropertyValue){ Name = (string)"Overwrite", Handle = (long)0x0, Value = (any){ (boolean)true }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE }, (com.sun.star.beans.PropertyValue){ Name = (string)"FilterData", Handle = (long)0x0, Value = (any){ ([]com.sun.star.beans.PropertyValue){ (com.sun.star.beans.PropertyValue){ Name = (string)"Sheet", Handle = (long)0x0, Value = (any){ (string)"Sheet2" }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE }, (com.sun.star.beans.PropertyValue){ Name = (string)"Select", Handle = (long)0x0, Value = (any){ (string)"A1:F19" }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE } } }, State = (com.sun.star.beans.PropertyState)DIRECT_VALUE })

A few questions that I need help with:

  1. Is the process to convert a spreadsheet to png pass through a conversion to PDF?
  2. Is it possible to select a specific sheet and range to convert it to an image?
  3. Why version 0.9.0 uses draw_png_Export as office filter and version 0.8.2 uses writer_png_Export office filter?
  4. Is it possible to force which office filter I would like to use?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant