I currently have a perl program in Windows that creates and populates an excel file via Spreadsheet::WriteExcel, but I'd like to have that file opened as my program closes. I tried googling for information, but all I found was how to open and read excel files within perl. Would anyone be able to help me?
我目前在Windows中有一个perl程序,它通过Spreadsheet :: WriteExcel创建并填充excel文件,但是我希望在我的程序关闭时打开该文件。我尝试使用Google搜索信息,但我发现的是如何在perl中打开和读取excel文件。有人能帮助我吗?
4 个解决方案
#1
3
I recommend this:
我推荐这个:
`your_file.xls`;
It just executes a system command. Assuming Excel files are set to default open with Excel, this will work (adding the full path to the file may or may not be necessary, depending on your setup).
它只是执行一个系统命令。假设Excel文件设置为使用Excel默认打开,这将起作用(根据您的设置,添加文件的完整路径可能是必要的,也可能不是必需的)。
Other options:
system("your_file.xls");
`C:\\Program Files\\...\\excel.exe your_file.xls`;
system("C:\\Program Files\\...\\excel.exe your_file.xls");
#2
2
I would use Win32::OLE for this. OLE is the Office extensions that you can use to perform tasks with the applications. This example should work (I haven't tested it):
我会为此使用Win32 :: OLE。 OLE是可用于执行应用程序任务的Office扩展。这个例子应该有效(我还没有测试过):
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
my $excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new( 'Excel.Application', 'Quit' );
$excel->{Visible} = 1;
If you end up going down this route, here's a reference to the Excel 2007 commands.
如果您最终沿着这条路线走下去,这里是对Excel 2007命令的引用。
#3
-1
The following works for me. It does not require using any additional module(s).
以下适用于我。它不需要使用任何其他模块。
system "start excel $file";
#4
-1
you can use the exec command in Perl like this:
您可以在Perl中使用exec命令,如下所示:
my $excel_file = "file.xlsx";
exec "cmd", "/c", "start", $excel_file;
This will open the default program in your system to open xlsx files. I like this option because if the user does not have excel installed, only libreoffice (for example), the system will open the file with libreoffice.
这将打开系统中的默认程序以打开xlsx文件。我喜欢这个选项,因为如果用户没有安装excel,只有libreoffice(例如),系统将使用libreoffice打开文件。
#1
3
I recommend this:
我推荐这个:
`your_file.xls`;
It just executes a system command. Assuming Excel files are set to default open with Excel, this will work (adding the full path to the file may or may not be necessary, depending on your setup).
它只是执行一个系统命令。假设Excel文件设置为使用Excel默认打开,这将起作用(根据您的设置,添加文件的完整路径可能是必要的,也可能不是必需的)。
Other options:
system("your_file.xls");
`C:\\Program Files\\...\\excel.exe your_file.xls`;
system("C:\\Program Files\\...\\excel.exe your_file.xls");
#2
2
I would use Win32::OLE for this. OLE is the Office extensions that you can use to perform tasks with the applications. This example should work (I haven't tested it):
我会为此使用Win32 :: OLE。 OLE是可用于执行应用程序任务的Office扩展。这个例子应该有效(我还没有测试过):
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
my $excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new( 'Excel.Application', 'Quit' );
$excel->{Visible} = 1;
If you end up going down this route, here's a reference to the Excel 2007 commands.
如果您最终沿着这条路线走下去,这里是对Excel 2007命令的引用。
#3
-1
The following works for me. It does not require using any additional module(s).
以下适用于我。它不需要使用任何其他模块。
system "start excel $file";
#4
-1
you can use the exec command in Perl like this:
您可以在Perl中使用exec命令,如下所示:
my $excel_file = "file.xlsx";
exec "cmd", "/c", "start", $excel_file;
This will open the default program in your system to open xlsx files. I like this option because if the user does not have excel installed, only libreoffice (for example), the system will open the file with libreoffice.
这将打开系统中的默认程序以打开xlsx文件。我喜欢这个选项,因为如果用户没有安装excel,只有libreoffice(例如),系统将使用libreoffice打开文件。