# 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?

edit retag close merge delete

Sort by » oldest newest most voted

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)



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

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

( 2017-12-31 13:52:43 +0100 )edit

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

( 2017-12-31 14:18:24 +0100 )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.

( 2017-12-31 15:27:02 +0100 )edit

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

( 2017-12-31 16:24:26 +0100 )edit

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

( 2017-12-31 17:39:32 +0100 )edit

So: do you use a correct output document path?

( 2017-12-31 17:59:21 +0100 )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!

( 2018-01-01 01:33:25 +0100 )edit

## Stats

Seen: 216 times

Last updated: Dec 31 '17