在 Windows 和 Linux 上使用 Perl 附加到 Excel 电子表格
我想附加到 Excel 电子表格。 Win32::OLE 与此完美配合,但它不适用于 Linux 计算机。 Spreadsheet::WriteExcel 似乎无法附加,但它可以在两个平台上工作。我发现了 Excel::Writer::XLSX,但它报告说它没有电子表格那么多的功能...
我还想创建超链接,因此单击某些文本将引导您到 Excel 中的另一个工作表作业簿。这可能吗?在哪一个(Excelwriter/等)上?
那么两个问题: 1) 我应该使用什么才能在两个平台上工作时附加到电子表格? 2) 是否可以创建超链接以指向其他工作表并使用哪一个?
以下是我用于附加新工作表的 Win32::OLE 的代码:
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
print "Opening Excel...\n";
$Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
#appending to existing excel file
my $book = $Excel->Workbooks->Open($full_name) || die "Error: Could not open Excel workbook";
#putting this sheet at the beginning
my $sheet = $book->Worksheets->Add({Before => $book->Worksheets(1)}) or die "Error: " . Win32::OLE->LastError;
I want to append to an Excel spreadsheet. Win32::OLE works perfectly with this, but it doesn't work on Linux machines. Spreadsheet::WriteExcel doesn't seem to be able to append while it can work on both platforms. I found out about Excel::Writer::XLSX, but it reports that it does not have as many features as Spreadsheet...
I would also like to create hyperlinks, so clicking on some text will lead you to another sheet in the Excel workbook. Is this possible and on which one (Excelwriter/etc)?
So two questions:
1) What should I use so I can append to spreadsheets while working on both platforms?'
2) Is it possible to create hyperlinks to lead to other sheets and using which one?
Here is the code I used for Win32::OLE that appended a new worksheet:
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
print "Opening Excel...\n";
$Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
#appending to existing excel file
my $book = $Excel->Workbooks->Open($full_name) || die "Error: Could not open Excel workbook";
#putting this sheet at the beginning
my $sheet = $book->Worksheets->Add({Before => $book->Worksheets(1)}) or die "Error: " . Win32::OLE->LastError;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是片面的,也许是无效的答案:
Use the open XML SDK for office。任何 *.xlsx 文件实际上都是 *.zip 文件,其中包含许多描述该文档的 xml 文件。使用 SDK,您可以在电子表格和工作簿之间建立链接。不幸的是它仅适用于 Windows...:(
This is partial and maybe a non-valid answer:
Use the open XML SDK for office. Any of the *.xlsx files are actually *.zip files with many xml files inside that describe the document. Using the sdk you could make links between spreadsheets and workbooks. Unfortunately it works on Windows only... :(