简体   繁体   English

在Linux机器上使用Java调用Excel宏

[英]Call Excel Macro using java on a linux box

I am not really sure if this is possible but here it goes , I have written an excel macro and i am calling this macro through a vbs. 我不确定这是否可行,但是我已经写了一个excel宏,并通过vbs调用了这个宏。 Here is the snippet for the same. 这是相同的代码段。

Dim objExcel, objWorkbook, ad, FilePath
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
For Each ad In objExcel.AddIns
    If ad.Name = "hello.xla" Then
        FilePath = ad.Path & "\hello.xla"
        Exit For
    End If
Next
objExcel.Workbooks.Open (FilePath)
Set objWorkbook = objExcel.Workbooks.Open(WScript.Arguments(0))
objExcel.Run "Test"
objWorkbook.Close
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
WScript.Echo "Finished."
WScript.Quit

I am able to do dis. 我能够做dis。 Now i am calling this vb script using java Runtime.getRuntime().exec("cmd /c start calling.vbs"); 现在,我使用java Runtime.getRuntime().exec("cmd /c start calling.vbs");调用此vb脚本Runtime.getRuntime().exec("cmd /c start calling.vbs");

So is it possible to run this excel macro on a linux server? 那么有可能在Linux服务器上运行此excel宏吗? I understand that we cannot call a vbs file on a linux box and also that opening and formatting the excel maybe not possible hence is there maybe a workaround or some other way to call it in linux machine maybe using an sh file ? 我知道我们不能在linux盒子上调用vbs文件,而且可能无法打开和格式化excel,因此是否有变通办法或某种其他方式在linux计算机中调用它,也许使用了sh文件?

In theory, you could install Excel and Visual Basic in wine and see if your macro runs there. 从理论上讲,您可以在wine安装Excel和Visual Basic,然后查看宏是否在其中运行。 You could then try to execute Runtime.getRuntime().exec("wine cmd /c start calling.vbs"); 然后,您可以尝试执行Runtime.getRuntime().exec("wine cmd /c start calling.vbs");

In reality, this sounds like a very complex way of shooting yourself into the foot badly . 在现实中,这听起来像是一种非常复杂的方法,使自己严重陷入脚下。

If you want it to run reliably on Linux, stay away from Excel and Visual Basic and start using server technology instead of old office technology. 如果希望它在Linux上可靠地运行,请远离Excel和Visual Basic,并开始使用服务器技术而不是旧的办公技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM