简体   繁体   English

使用带有OLE的Perl从Excel中的可变列数获取数据

[英]Getting data from a variable number of columns in Excel using Perl with OLE

I am using OLE with Perl to build a few charts in Excel. 我在Perl中使用OLE在Excel中构建一些图表。 The data is in four different worksheets depending on which of the four tests it is for. 数据位于四个不同的工作表中,具体取决于它用于四个测试中的哪个。 The problem is that I don't know how to set the chart to look at all of the data when I don't know how long it will be. 问题是,当我不知道要多长时间时,我不知道如何设置图表以查看所有数据。

I know to use; 我知道用;

$last_col = $sheet -> UsedRange -> Find({What => "*", SearchDirection => xlPrevious, SearchOrder => xlByColumns}) -> {Column};

To get the last column with data in it. 要获取其中包含数据的最后一列。 But I can't go 但是我不能去

my $Range = $Sheet->Range("a1:$last_col3");

To set the range (obviously) 设置范围(显然)

Any ideas how to set the range to include to the last column? 有什么想法如何设置要包括到最后一列的范围? Or would it be best just to add each column to the chart individually? 还是最好将每个列分别添加到图表中?

Thanks! 谢谢!

There's no reason why you shouldn't be able to use 没有理由不应该使用

$sheet->range( "A1:${last_col}3" )

It works for me. 这个对我有用。

Ok, I've found a way. 好的,我找到了一种方法。 Not sure how good this is, but it works. 不知道这有多好,但它能起作用。

Instead of putting the variable into the range value, name the last cell which is interesting: 而不是将变量放入范围值,而是命名最后一个有趣的单元格:

$sheet -> Cells ($last_row,$last_col) -> {Name} = "LastCell";

And then use this in the range field; 然后在范围字段中使用它;

my $Range = $Sheet->Range("a1:LastCell");

Not the most elegant bit of coding I've every performed, but it works. 并不是我执行过的最优雅的编码方式,但是它可以工作。

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

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