Thank you so much, this worked perfectly. We’re even able to decrypt it from gmail.
For some reason every time I specified the “FilterName” as “Calc MS Excel 2007 XML” it didn’t encrypted the file.
This is the script right now
sub SaveWithPassword(inputFile as String, outputFile as String, password as String) as Integer
' Convert file paths to a format LibreOffice can undersntad
dim inputFileURL as string
inputFileURL = ConvertToURL(inputFile)
dim outputFileURL as String
outputFileURL = ConvertToURL(outputFile)
' Properties used to load the component
dim loadComponentProperties(0) As New com.sun.star.beans.PropertyValue
' Don't launch a new window when loading the document
loadComponentProperties(0).Name = "Hidden"
loadComponentProperties(0).Value = True
' If an error occured, jump to handleError label
on error goto handleError
' Load the document
dim doc as Object
doc = stardesktop.LoadComponentFromURL(inputFileURL, "_blank", 0, loadComponentProperties)
' Output document encryption data
Dim encryptionData(1) As New com.sun.star.beans.NamedValue
encryptionData(0).Name = "CryptoType"
encryptionData(0).Value = "Standard"
encryptionData(1).Name = "OOXPassword"
encryptionData(1).Value = password
' Properties used when saving the document
dim saveEncryptedArgs(1) As New com.sun.star.beans.PropertyValue
saveEncryptedArgs(0).Name = "FilterName"
saveEncryptedArgs(0).Value = "Calc MS Excel 2007 XML"
saveEncryptedArgs(1).Name = "EncryptionData"
saveEncryptedArgs(1).Value = encryptionData
' Store this docuemnt with a password where specified.
' Using storeAsURL might be preferred in our case, since we want to overwrite the documents
' doc.storeToURL(outputFileURL, saveEncryptedArgs)
doc.storeAsURL(outputFileURL, saveEncryptedArgs)
' Close the document
doc.close(True)
' Return '1' (true) if succesfull
SaveWithPassword = 1
exit sub
handleError:
' Return '0' (false) if an error occured
SaveWithPasswor2 = 0
end sub
I may have just one last question. Is there a way to return a value from the script?
Because when I run the script from C++ it always returns 0 (I have other ways to verify that the script worked).