Ask Your Question
0

Macro for server side image generation of spreadsheet

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

tagussan gravatar image

updated 2017-12-31 07:38:45 +0100

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

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

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

edit flag offensive delete link more

Comments

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

tagussan gravatar imagetagussan ( 2017-12-31 15:27:02 +0100 )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 +0100 )edit

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

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

So: do you use a correct output document path?

Mike Kaganski gravatar imageMike Kaganski ( 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!

tagussan gravatar imagetagussan ( 2018-01-01 01:33:25 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 102 times

Last updated: Dec 31 '17