[英]Perl Excel - Inserting an empty row with row,col numbers from vairable
When trying to insert an empty row using the following code 当尝试使用以下代码插入空行时
my $StartRow = "101";
我的$ StartRow =“ 101”; my $StartCol = "1";
我的$ StartCol =“ 1”;
$Sheet->Cells($StartRow,$StartCol)->EntireRow->Insert;
$ Sheet-> Cells($ StartRow,$ StartCol)-> EntireRow-> Insert;
Error Occurred: Win32::OLE(0.1709) error 0x800a03ec in METHOD/PROPERTYGET "Cells" at 1_SPNV3G_WSS-MGW_1_0_Chicago.pl line 1732. 发生错误:在1_SPNV3G_WSS-MGW_1_0_Chicago.pl第1732行处,METHOD / PROPERTYGET“单元”中的Win32 :: OLE(0.1709)错误0x800a03ec。
Win32::OLE(0.1709) error 0x80010108: "The object invoked has disconnected from its clients" in METHOD/PROPERTYGET "Close" at 1_SPNV3G_WSS-MGW_1_0_Chicago.pl line 6310. Win32 :: OLE(0.1709)错误0x80010108:1 / SPNV3G_WSS-MGW_1_0_Chicago.pl第6310行的METHOD / PROPERTYGET“ Close”中的“调用的对象已与其客户端断开连接”。
Where as if I give the the values directly, no issue observed. 好像我直接给出值一样,没有发现问题。
$Sheet->Cells(101,1)->EntireRow->Insert;
$ Sheet-> Cells(101,1)-> EntireRow-> Insert;
Any thoughts? 有什么想法吗?
PS I am referring this thread for Insert row. PS我指的是该线程插入行。 http://www.perlmonks.org/?node_id=882700
http://www.perlmonks.org/?node_id=882700
Because, Perl infers the types of variables dynamically. 因为,Perl动态地推断变量的类型。 Variables
$StartRow
and $StartCol
are considered as strings as you enclosed their assigned values in quotes. 将变量
$StartRow
和$StartCol
括在引号中时,它们被视为字符串。 Remove the quotes and they'll work, as the 'Cells' method expects integers as arguments. 删除引号,它们将起作用,因为'Cells'方法期望使用整数作为参数。 or try
或尝试
$StartRow = int ($StartRow);
$StartCol = int ($StartCol);
This should work. 这应该工作。 I encountered this recently while doing this
我最近在这样做时遇到了这个
my ($i, $j) = split (/\s*,\s*/, $address);
print "\n".$sheet->Cells($i, $j)->{Value};
Here the values returned from the split operation were considered as strings. 在这里,从分割操作返回的值被视为字符串。 Then I converted them to integers and it worked.
然后,我将它们转换为整数,并且可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.