简体   繁体   English

使用Perl解析Excel文件

[英]Parse excel file with using Perl

I'm quite new in perl, so I'm asking for tips for the problem below : I have a excel file and I want to search for specific words in column title (1st row) then if it matches I extract the entire column and put it in a array (or whatever else). 我是perl的新手,所以我想问以下问题的技巧:我有一个excel文件,我想在列标题(第1行)中搜索特定的单词,然后如果匹配则提取整列并将其放入数组(或其他任何数组)中。

So in my array, I will have first column then 2nd etc... until the end of the search. 所以在我的数组中,我将有第一列,然后是第二列,等等……直到搜索结束。

I'm intending after that to read my array line by line to process data in order (I'm confortable for that part). 我打算在那之后逐行读取我的数组以按顺序处理数据(对此我感到很舒服)。

thanks 谢谢

Take a look at Spreadsheet::Read . 看看Spreadsheet :: Read It reads the whole Excel sheet in an array-hash-ref, which you can search. 它以array-hash-ref读取整个Excel工作表,您可以搜索该表。

Look at Spreadsheet::Read. 看一下Spreadsheet :: Read。 The results come out $ref->{cell}->[arrayref_of_columns] so you can match against index [1] of that array ref and if it matches, that whole arrayref is your column. 结果来自$ ref-> {cell}-> [arrayref_of_columns],因此您可以与该数组ref的索引[1]进行匹配,如果匹配,则整个arrayref就是您的列。

Personally, I always prefer to export Excel files to XML format using Save as->XML Spreadsheet 2003 and use XML::Simple . 就个人而言,我总是更喜欢使用Save as->XML Spreadsheet 2003将Excel文件导出为XML格式,并使用XML::Simple However, there are a few Excel parsers too. 但是,也有一些Excel解析器。

Spreadsheet::ParseExcel and Spreadsheet::XLSX , of which you probably want the latter. Spreadsheet :: ParseExcelSpreadsheet :: XLSX ,您可能需要后者。

NOTE: I haven't used ReadExcel, but it looks good too. 注意:我还没有使用ReadExcel,但它看起来也不错。

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

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