Libreoffice . docx Macro - PHP

Asked

Viewed 45 times

1

Hello,

Is it possible to run a libreoffice macro by php? something like:

"c:/Program Files/LibreOffice/program/soffice" --nologo --norestore --nolockcheck "macro:///Standard.Module2.PysIndexer(C:\wamp\www\site\public\file.docx)"

Macro:

sub PysIndexer(docPath as string)

dim document as object
dim dispatcher as object
dim pdfPath as string

dim args1(0) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue

if fileExists(docPath) then

    args1(0).Name = "Hidden"
    args1(0).Value = True

    args2(0).Name = "FilterName"
    args2(0).Value = "writer_pdf_Export"

    document = starDesktop.loadComponentFromUrl(convertToUrl(docPath), "_blank", 0, args1())

    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document.CurrentController.Frame, ".uno:UpdateAllIndexes", "", 0, array())

    GlobalScope.BasicLibraries.LoadLibrary("Tools")
    pdfPath = GetFileNameWithoutExtension(docPath) & ".pdf"
    document.storeToURL(convertToUrl(pdfPath), args2())

    document.close(True)
end if

end sub

The command works if it runs in windows, but it doesn’t work using php’s exec or shell_exec. My question is whether the macro note:/// is only recognized by the windows user and if there is some other way to call the macro so php can recognize.

I found this macro on the following link and ended up updating the code a little. https://ask.libreoffice.org/en/question/46586/how-to-automatically-update-indices-in-headless-mode/

PS. I still don’t know if this is the best solution, but it was the only one I found for now to update "automatically" the summary of a file with libreoffice without the option to update manually (open the file update the summary and close).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.