Macro for server side image generation of spreadsheet

Hi,

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?

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:

oDoc.setModified(False)
oDoc.close(True)

oSpreadsheet.setModified(False)
oSpreadsheet.close(True)

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).

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”.

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

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.

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

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

So: do you use a correct output document path?

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

By the way, happy new year!