List Info

Thread: Get the rowid in Excel using perl




Get the rowid in Excel using perl
country flaguser name
United States
2007-08-23 15:10:24

Hi,
My program is to read a excel file.
Search for a value in the first column of the file.
And get the row number for that value found in the file.
I have got the code to work to find the value but I am not able
to find the number.
Can someone please help me.
Thanks,
Rama

#!/usr/bin/perl
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die
on errors...
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit'); # get already
active Excel
#
application or open new
my $Book = $Excel->;Workbooks->Open("C:\test.xls";); # open Excel file
my $Sheet = $Book->Worksheets(3); # select worksheet number 1
my $array = $Sheet->;Range("A1:A19")->{'Value'}; # get the
contents
my $test_id1 = "107";
$Book->Close;
foreach my $ref_array ($array) { # loop
through the array
$count++; # referenced by $array
foreach my $scalar ($ref_array)
{
$count++;
if ($test_id1 =~ m/$scalar/)
{
print "Found";

}
}
}

__._,_.___
.

__,_._,___
Re: Get the rowid in Excel using perl
country flaguser name
United States
2007-08-24 04:56:15

Hi,

Your code is working well in my system.

I think, you need to check in your excel.

Regards
Vijay

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "ramaparvathi"
<ramaparvathi...> wrote:
&gt;
> Hi,
> My program is to read a excel file.
&gt; Search for a value in the first column of the file.
&gt; And get the row number for that value found in the file.
&gt; I have got the code to work to find the value but I am not able
> to find the number.
> Can someone please help me.
> Thanks,
> Rama
>;
> #!/usr/bin/perl
>; use strict;
> use Win32::OLE qw(in with);
&gt; use Win32::OLE::Const 'Microsoft Excel';
> $Win32::OLE::Warn = 3; # die
> on errors...
> my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
> || Win32::OLE->new('Excel.Application', 'Quit'); # get already
> active Excel
&gt; #
> application or open new
> my $Book = $Excel->;Workbooks->Open(&quot;C:\test.xls";); # open Excel
file
> my $Sheet = $Book->Worksheets(3); # select worksheet number 1
> my $array = $Sheet->;Range(&quot;A1:A19&quot;)->{'Value'}; # get the
> contents
> my $test_id1 = "107&quot;;
&gt; $Book->Close;
&gt; foreach my $ref_array ($array) { # loop
> through the array
&gt; $count+;+; # referenced by $array
&gt; foreach my $scalar ($ref_array)
> {
> $count+;+;
> if ($test_id1 =~ m/$scalar/)
> {
> print "Found";
>
> }
> }
> }
>

__._,_.___
.

__,_._,___
Re: Get the rowid in Excel using perl
country flaguser name
United States
2007-08-24 06:11:32

Hi
Try the following code. It prints the row number

Regards
Vijay

#!/usr/bin/perl
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
my $Excel = Win32::OLE-> GetActiveObject('Excel.Application') ||
Win32::OLE-> new('Excel. Application' , 'Quit'); # get already active
Excel application or open new
my $Book = $Excel->;Workbooks->Open(&quot;C:\test.xls";); # open Excel file
my $Sheet = $Book->Worksheets(3); # select worksheet number 1
my $array = $Sheet->;Range(&quot;A1:A19&quot;)->{'Value'}; # get the contents
my $test_id1 = "107&quot;;
$Book->Close;
my $count = 0;

foreach my $ref_array ($array)
{ # loop through the array
$count++; # referenced by $array
foreach my $scalar ($ref_array)
{
#$count+;+;
if ($test_id1 =~ m/$scalar/)
{
print $count;
#print "Found";
}
}
}

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "ramaparvathi&quot;
<ramaparvathi...> wrote:
&gt;
> Hi,
> My program is to read a excel file.
&gt; Search for a value in the first column of the file.
&gt; And get the row number for that value found in the file.
&gt; I have got the code to work to find the value but I am not able
> to find the number.
> Can someone please help me.
> Thanks,
> Rama
>;
> #!/usr/bin/perl
>; use strict;
> use Win32::OLE qw(in with);
&gt; use Win32::OLE::Const 'Microsoft Excel';
> $Win32::OLE::Warn = 3; # die
> on errors...
> my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
> || Win32::OLE->new('Excel.Application', 'Quit'); # get already
> active Excel
&gt; #
> application or open new
> my $Book = $Excel->;Workbooks->Open(&quot;C:\test.xls";); # open Excel
file
> my $Sheet = $Book->Worksheets(3); # select worksheet number 1
> my $array = $Sheet->;Range(&quot;A1:A19&quot;)->{'Value'}; # get the
> contents
> my $test_id1 = "107&quot;;
&gt; $Book->Close;
&gt; foreach my $ref_array ($array) { # loop
> through the array
&gt; $count+;+; # referenced by $array
&gt; foreach my $scalar ($ref_array)
> {
> $count+;+;
> if ($test_id1 =~ m/$scalar/)
> {
> print "Found";
>
> }
> }
> }
>

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )