如何在 Mac 上编写 Excel 或 Numbers 脚本并从 bash 启动?
我想为 Mac 编写一个 bash 脚本,它获取包含数字表(可以是 .csv)的文本文件,将数字转换为图表,保存图表(我可以在网页上显示的任何文件格式) ,然后退出。它必须在无人值守的情况下执行此操作。没有用户交互。
我懂 bash、perl 和一点 AppleScript,我还可以学习 VBA 或其他任何东西。我正准备砸钱购买新的 Excel 2011 for Mac。我认为我想要 Excel 而不是 Numbers'09,但我一点也不确定,并且我认为 VBA 或 AppleScript 将允许我自动化大部分工作。
AppleScript + Excel 是一个不错的选择吗?如果是这样,那么我就自由回家了。 Applescript 程序可以通过 osascript 命令从 bash 启动。
但也许 VBA 更好?但是如何在 Mac 上从 bash 启动 Excel VBA 脚本?
问题总结: (1) AppleScript 还是 VBA 还是其他? (2) Excel 还是 Number? (3) 如何从bash启动Excel VBA脚本?
提前致谢, 肯
I want to write a bash script for a mac which takes a text file containing a table of numbers (can be .csv), converts the numbers to a chart, saves the chart (any file format that I can display on my web page), and exits. It must do this unattended. No user interaction.
I know bash, perl, and a little AppleScript, and I can learn VBA or whatever else. I am about to plunk down money for the new Excel 2011 for Mac. I think I want Excel rather than Numbers'09, but I am not at all sure, and I think VBA or AppleScript will allow me to automate most of the work.
Is AppleScript + Excel a good choice? If so, then I'm home free. Applescript programs can be launched from bash via osascript command.
But maybe VBA is better? But how can I launch a Excel VBA script from bash on a mac?
Summary of questions: (1) AppleScript or VBA or something else? (2) Excel or Numbers? (3) How to launch Excel VBA script from bash?
Thanks in advance,
Ken
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Microsoft 在 v2008 中删除了 Office 中的 VBA 支持。 iWork '08 不支持 Applescript,虽然鉴于 Apple 最近在可编写脚本的应用程序方面的下降,我无法直接谈论 v'09,但我不会指望它。
可以肯定的是,长期的赌注是使用 Excel 和 Applescript。
Microsoft removed VBA support from Office with v2008. iWork '08 has no Applescript support, and while I can't speak directly about v'09 given Apple's recent decline in scriptable applications I wouldn't count on it.
The sure, long-term bet here would be to use Excel with Applescript.
不要忘记尝试 OpenOffice(及其衍生产品)。自从我上次使用它以来已经有一段时间了,但是他们有宏语言和一些 VBA 支持(不知道它现在有多好,我确信它已经进步了) - 所以它可能会为你生成图表。
或者,这听起来像是 Gnuplot 可以很容易做到的事情。请参阅这篇文章,他们从文本文件中的原始数据开始,创建一个用于网页的 PNG 文件: http://www.ibm.com/developerworks/aix/library/au-gnuplot/index.html
只是认为您应该了解 Excel 之外的其他选项数字...
Don't forget to try OpenOffice (and derivatives). It's been a while since I last worked with it, but they have a macro language and some VBA support (don't know how good it is now, I'm sure it's progressed) - so it could likely generate your graphs for you.
Alternatively, this sounds like something Gnuplot could very easily do. See this article where they start with the raw data in a text file, and create a PNG file for use in a web page: http://www.ibm.com/developerworks/aix/library/au-gnuplot/index.html
Just thought you should know about other options than Excel and Numbers...
您应该明确考虑使用 gnuplot(免费),它可以通过命令行从不同的输入文件格式轻松创建图形甚至 HTML5 画布元素。
You should definitively consider using gnuplot (free), which can easily create graphics and even HTML5 canvas elements from different input file formats via the command line.
iWork 09 确实支持Applescript。 Pages 的支持非常好。数字远不那么重要。我认为大多数人都希望新版本能提供更广泛的 Applescript 支持,因为 Numbers 仅提供部分支持。因此,对于最初的问题,您确实需要使用 Excel。
如果您要编写脚本,我会认真考虑 Python 或 Ruby 与 Appscript 的结合,而不是 Applescript 或 VBA。 Applescript 是一种可以用其他语言编写的语言,并且使用其他语言之一可以为您提供该语言的所有库。这允许编写更强大的代码。
如果您只是为 Office 编写并且不需要太多其他功能,那么我可能会坚持使用 VBA。
iWork 09 does support Applescript. Pages is pretty good with its support. Numbers far less so. I think most expect more expansive Applescript support with the new version as Numbers only has partial support. So for what the original question asks you really need to use Excel.
If you are going to script I'd look seriously at Python or Ruby combined with Appscript rather than Applescript or VBA. Applescript is a bear of a language to write in and using one of the other languages gives you all the libraries of that language. That allows quite a bit more powerful code to be written.
If you are just writing for Office and don't need much other functionality then I'd probably stick with VBA.
您可能想看看 Google 图表工具。
它对于在网页中包含图表和图形非常有用。
您只需创建一个包含数据的 URL 作为图像的
src
,然后 tada 就会出现。玩一玩。
例如,一些参数:
创建一个网址:https://chart.googleapis.com/chart?chd=t:10,20,30&chco=FF0000|00FF00|0000FF&chs=320x240&cht=p3&chdl=Red |Green|Blue
形成图表:
You might like to take a look at Google Chart Tools.
It is exceptionally useful for including charts and graphs within web pages.
You just create a URL containing the data as a
src
for an image, then tada, it appears.Have a play.
For instance, a few parameters:
Makes a URL: https://chart.googleapis.com/chart?chd=t:10,20,30&chco=FF0000|00FF00|0000FF&chs=320x240&cht=p3&chdl=Red|Green|Blue
Which forms a chart:
如果您使用的是 OS X,我建议您使用 Numbers 和 AppleScript——它们集成得很好。此外,您还可以使用 Automator 让您的生活变得更加简单。
I would recommend using Numbers and AppleScript if you are on OS X—these are well integrated. Also, you could use Automator to make your life even simpler.