We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Macro for server side image generation of spreadsheet [closed]

asked 2017-12-31 07:36:23 +0200

tagussan gravatar image

updated 2021-06-10 11:01:17 +0200

Alex Kemp gravatar image


I have an ods file, which has only one sheet. I'd like to generate PNG file of the sheet. However, if I use "File -> Export...", I got PNG files which is splitted into page. What I need is a PNG file as single image, not the splitted one.

Then I came up with an idea. First, I select the necessary area, copy, and paste it to Writer, like "(Right click on page) -> Paste spetial -> More options -> Bitmap". Then I right-clicked the pasted bitmap object and did "Save" in the context menu. With this method I was succeeded in generating the single PNG image manually, so I tried to automate this procedure, using Macro. Finally I like to do this on server side.

To ask opinion, I made this question yesterday, and received awesome macro (Thanks Mr. Jim K!). However, this macro does not run in headless mode. I want to do this on server side. Specifically, I want to run the macro from shell, like "soffice --headless --norestore --nofirststartwizard --invisible "macro:///Standard.Module1.SaveSheetAsBitmap()" test.ods"

What kind of method is available to achieve this?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2021-02-11 02:48:14.048590

1 Answer

Sort by » oldest newest most voted

answered 2017-12-31 09:27:33 +0200

The macro provided in the referenced topic creates a new Draw document and pastes an image to it. This, naturally, sets Modified flag to it.

Also, as there's no command in your command line that implies opening, doing something, and then closing, the files aren't attempted to close at all (LO expects that you will do something to the documents later, like using UNO commands).

You may append the following lines to that macro:



This closes both documents, setting Modified to False (this might be required also for spreadsheet as well, because of a bug that some charts set Modified flag on opening).

edit flag offensive delete link more


I added the lines to the macro; however the command line does not return. After some experiment, the soffice command returnes when I append the suggested lines and commented out the line: "oExporter.Filter(aExportProps)". It seems that I need to append some additional code for "GraphicExportFilter".

tagussan gravatar imagetagussan ( 2017-12-31 13:52:43 +0200 )edit

Well: does it create the image at least, when you don't comment out that line?

Mike Kaganski gravatar imageMike Kaganski ( 2017-12-31 14:18:24 +0200 )edit

If I comment out that line, no image is created.

I'm sorry to say that I needed to comment out not only "oExporter.Filter(aExportProps)", but also "oExporter.SetSourceDocument(oDocController.Selection)" to return from soffice command.

tagussan gravatar imagetagussan ( 2017-12-31 15:27:02 +0200 )edit

does it create the image at least, when you don't comment out that line?

Mike Kaganski gravatar imageMike Kaganski ( 2017-12-31 16:24:26 +0200 )edit

Oops! If I don't comment out that line, no image is created, too.

tagussan gravatar imagetagussan ( 2017-12-31 17:39:32 +0200 )edit

So: do you use a correct output document path?

Mike Kaganski gravatar imageMike Kaganski ( 2017-12-31 17:59:21 +0200 )edit

Yes. If I run this macro not from command line but from LibreOffice GUI, this macro works correctly.

By the way, happy new year!

tagussan gravatar imagetagussan ( 2018-01-01 01:33:25 +0200 )edit

Question Tools

1 follower


Asked: 2017-12-31 07:36:23 +0200

Seen: 228 times

Last updated: Dec 31 '17