使用Perl在excel中搜索具有值的所有行 [英] Search for all rows with values in excel with perl

查看:42
本文介绍了使用Perl在excel中搜索具有值的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用perl将来自excel的数据解析为特定的XML格式,然后由另一个应用程序读取该XML格式,然后创建该数据的图形表示形式.Excel工作表会定期由数据捕获器更新.我选择了Spreadsheet :: Read模块,但是遇到了问题.

I am trying to parse data from excel using perl into a specific XML format, which is read by another application, which then creates a graphical representation of the data. The excel sheet gets updated by data capturers on a regular base. I have opted for the Spreadsheet::Read module but I am having an issue.

该工作表将被划分为特定的单元格,该单元格对应于特定的布局.该工作表将因此具有:

The sheet would be divided into specific cells, which corresponds to a specific layout. The sheet will thus have:

国家|城市|郊区|链接

Country | City | Suburb | link

每行都是不同的数据,等等.

Each row being different data etc.

我试图告诉脚本获取这样的每一行.

I tried to tell the script to get every row like this.

    use Spreadsheet::Read;

    my $book  = ReadData ("Captured_input.xlsx");
    my @rows = Spreadsheet::Read::rows ($book->[1]);

    print "@rows\n";

这会打印ARRAY(和一些十六进制数据)但是,我希望它读取每一行和单元格并像这样返回它:

This however prints ARRAY(and some hex data) However, I want it to read each row and cell and return it like this:

国家1,城市1,郊区1,链接1

Country1, City1, Suburb1,link1

Country2,City2,Suburb2,link2

Country2, City2, Suburb2,link2

它每天运行一次,因此它不应该只读取文件末尾,而是应该每次读取整个工作表,因此,如果进行了任何更改,它将重新发布XML.

It runs on a daily base so it should not read end of file only, it should read the entire sheet each time, so if any changes were made it will republish the XML.

如果我这样使用它,它可以工作并返回数据,但是我需要手动指定每一行,但是我无法估计将来会有多少行.

If I use it like this, it works and returns the data, but I then need to manually specify each row, but I cannot estimate how many rows there will be in future.

    use Spreadsheet::Read;

    my $book  = ReadData ("Captured_input.xlsx");
    my @row = Spreadsheet::Read::cellrow ($book->[1], 4);

    print "@row\n,";

不胜感激.

推荐答案

  1. 阅读 perlreftut .
  2. 阅读 perldsc .
  3. 阅读电子表格::阅读文档.

文档很好地显示了 $ book 将包含的数据结构.一旦了解了引用的工作方式(请参阅前两个链接),就可以轻松处理数据.

The documentation shows quite well what data structure the $book will contain. Once you understand how references work (see the first two links), handling the data will be easy.

这篇关于使用Perl在excel中搜索具有值的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆