用于 CSV 保存的 openoffice calc 宏
给定:我在 Openoffice 中录制了一个简单的宏,将工作表保存为 CSV 文件。这里是。
sub toCSV
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///path/csv/filename.csv"
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
问题:我想给这个函数添加一些功能。 1. 我需要获取当前的 XLS 文件名,以便将其放在静态路径的末尾。因此 file:///path/csv/ 将始终保持不变,并且 filename.csv 将来自 filename.xls。 2. 好吧,我需要对 filename-revision01.xls 进行一些正则表达式替换,以最终获得 filename.csv。
我可以很好地进行正则表达式匹配,我只是在寻找有关字符串连接、如何获取当前文件名以及如何在宏中编写正则表达式的提示。
顺便说一句,这种语言叫什么!?
Given: I recorded a simple macro in Openoffice to save my worksheet as a CSV file. Here it is.
sub toCSV
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///path/csv/filename.csv"
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
Problem: I want to add some features to this function. 1. I need to get the current XLS filename so that I can put that at the end of my static path. So file:///path/csv/ is going to always remain the same, and filename.csv will be coming from filename.xls. 2. Well, I'll need to do some regex replacement on that filename-revision01.xls to ultimately get filename.csv.
I can do regex matching well, I'm simply looking for hints on string concatenation, how to get the current filename, and how to write a regex expression within a macro.
BTW, what is this language called!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我想出的解决方案,可帮助我一键导出 CSV(包含导出选项、文件名调整和文件位置)。
我使用的是 Mac,因此文件路径适用于此类操作系统。帮助我做到这一点的信息位于此处。
下面是上面宏所依赖的一些 javascript。该文件名为 ~/Library/Application\ Support/OpenOffice.org/3/user/Scripts/javascript/Tools/Regex.js,并在上面进行了硬编码和引用。
最后,这篇文章提供了详细信息了解如何添加工具栏按钮以一键运行宏。
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.
Here is a bit of javascript that the above macro relies upon. This file is named ~/Library/Application\ Support/OpenOffice.org/3/user/Scripts/javascript/Tools/Regex.js and is hardcoded and referenced above.
Finally, this post gives details on how to add a toolbar button to run your macro with one click.