This is the solution I came up with to help in exporting a CSV (with my export options, filename adjustment, and file location) with one click.
I m on a Mac, so the file paths will be for such an operating system. The information that helped me do this is here.
REM ***** BASIC *****
sub toCSV
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
FileURL = ThisComponent.URL
oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
oMasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
oScriptReplace = oMasterScriptProvider.getScript("vnd.sun.star.script:Tools.Regex.js?language=JavaScript&location=user")
sReturn = RegExpReplace(oScriptReplace, FileURL, "(.*)/(w*-w*)(-revisiond*)+.xls", "i", "$2.csv")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///Users/joe/Documents/mydocuments/trunk/my%20projects/dictionary/verbsXLS/proofed/csv/" + sReturn
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "FilterOptions"
args1(2).Value = "59,34,76,1"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
end sub
function RegExpReplace(oScriptReplace as Object, sSource as String, sRegExp as String, sGlobUpcase as String, sReplace as String) as String
RegExpReplace = oScriptReplace.invoke(Array(sSource, sRegExp, sGlobUpcase, sReplace ), Array(), Array())
end function
这里是上述宏观依靠的 j脚石。 该档案名称为~/Library/Application。 Support/OpenOffice.org/3/user/codes/javascript/Tools/Regex.js, 上文硬编码和参考。
sSource = String(ARGUMENTS[0])
sRegExp = String(ARGUMENTS[1])
sGlobUpcase = (ARGUMENTS[2])
sReplace = String(ARGUMENTS[3])
myRe = new RegExp(sRegExp, sGlobUpcase)
ret = sSource.replace(myRe, sReplace)
最后,,这一员额详细介绍了如何添加一个工具条条条令,以一个点击来管理你的宏观。