Ask Your Question

How to append date variable in macro to export to .pdf file?

asked 2018-01-03 17:51:08 +0100

Montyj gravatar image

In LO calc, I have a simple macro to export a single sheet to a .pdf file. This export line works:

oDoc.storeToURL("file:///home/username/Desktop/Spreadsheets/test.pdf", aMediaDescriptor())

But I need to append the current simple date to the filename, trying this:

oDoc.storeToURL("file:///home/monty/Desktop/Spreadsheets/test'$(date +%Y-%m-%d)'.pdf", aMediaDescriptor())

That saves the filename literally as:

test'$(date +%Y-%m-%d)'.pdf

I have tried various combinations of parenthesis and quotes but am missing something!


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-01-03 21:50:24 +0100

Jim K gravatar image

updated 2018-01-04 01:49:42 +0100

Many things are easier in Python-UNO. This saves as test2018-01-03.pdf.

import datetime
today =
filename = "file:///home/monty/Desktop/Spreadsheets/test%s.pdf" % today
oDoc = XSCRIPTCONTEXT.getDocument()
oDoc.storeToURL(filename, aMediaDescriptor)

For more details, see my answer at

There are also a number of solutions for Basic given at It looks like the best way is to use service


Here is Basic code.

sDatestamp = Format(Now(),"YYYY-MM-DD")
filename = "file:///home/monty/Desktop/Spreadsheets/test" & sDatestamp & ".pdf"
oDoc = ThisComponent
oDoc.storeToURL(filename, aMediaDescriptor)

Based on @Mike Kaganski's comment, it seems the link I posted from the OOo forum is partly out of date. "MMMM" now works properly.

edit flag offensive delete link more



Re: "It looks like the best way is to use service": this shows that Format function can easily be used in Basic.

Mike Kaganski gravatar imageMike Kaganski ( 2018-01-03 22:33:54 +0100 )edit
Login/Signup to Answer

Question Tools


Asked: 2018-01-03 17:51:08 +0100

Seen: 155 times

Last updated: Jan 04 '18