in reply to Re^3: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column
in thread How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column

yes. It;s Windows 7
  • Comment on Re^4: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column

Replies are listed 'Best First'.
Re^5: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column
by rockyurock (Acolyte) on Feb 23, 2017 at 09:23 UTC
    on win32::OLE only reads .xls application but Iam using Windows 7 with .xlsx format. Is there any similar Utility In windows 7 as well ?
      win32::OLE only reads .xls

      What error message do you get with .xlsx ?

      Run this to show your versions

      #!perl use strict; use warnings; use Win32::OLE; # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); print "Perl $] Win32::OLE Version ${Win32::OLE::VERSION}\n"; print "Running Excel $Excel->{'Version'} on $Excel->{'OperatingSystem +'}\n";
      poj
        I have modified the program and now I am able to get the excel data Into a text file to be used as keywords. I want these keywords to be searched from no of files (main_log here) but not able to get the output like I want . My Input Data
        8077 8116 D type hexa usim = 1, isim = 1 8077 8116 D type hexa usim = 1, isim = 1 pcscf_v4 : num = 2, protocol_type = 0x21, port_num = 0, addr = 10.56.5 +.85 8088 1223 D temp sim_invalid = 0 8099 1223 XX is_ems_support = 1 #88 8099 1224 XX pdn_act_ind->pcscf_discovery_flag = 1 ind->signaling_flag = 1 some text here plmn = 405872 DefaultStatusBarPlmnPlugin: into updateCarrierLabel ipv6 = 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161 get_ipv6_prefix,temp ipv4 = 10.167.185.101 _send_ipv4_notify info.is_ems_support = 1 act_ind->emergency_indication = 1 access_rat_type = 0 transaction_id = 2, rat_type = 0

        Variables to read from Excel sheet :

        isim = usim = sim_invalid = pcscf_discovery_flag signaling_flag ran_type emergency_ind rat pcscf_v4 pcscf_v6 plmn is_ems_support ipv4 ipv6

        #!/usr/bin/env perl use strict; use warnings; my $ex = ''; my $book = ''; my $sheet = ''; my $data = ''; my $my_data = 0; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; # use existing instance if Excel is already running eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } $book = $ex->Workbooks->Open("E:\\Automation Related\\Perl Scripts - A +LL\\IMS_debugging\\Excel\\UE_NW_Parameters.xlsx"); $sheet = $book->Worksheets(1); $data = $sheet -> Range("A1:B2873") -> {Value}; # Opening the Output file for exporting the Excel data Into Text File open(FILE, ">excel_data.txt"); foreach my $cell_ref (@$data) { foreach my $my_data (@$cell_ref){ print FILE ($my_data); } print FILE "\n"; } close FILE; # Opening excel data File here open( my $kw, '<', 'excel_data.txt') or die $!; my @keywords = <$kw>; chomp(@keywords); # remove newlines at the end of keywords #get list of files in current directory my @files = <main_log*>; # loop over each file to search keywords in foreach my $file (@files) { open(my $fh, '<', $file) or die $!; my @content = <$fh>; close($fh); my $l = 0; my $outfile = 'excel_match'.$file.'.txt'; print "Check the output generated In file $outfile\n"; open my $fh_out, '>', $outfile or die "$!"; foreach my $kw (@keywords) { my $search = quotemeta($kw); # otherwise keyword is used as re +gex, not literally foreach (@content) { # go through every line for this keyword $l++; if (/\Q$search/) { print $fh_out "%s in file %s, line %d:%s'.$/, +$kw, $file, $l, $_"; last; } } } }

        My input data to search from: 8077 8116 D type hexa usim = 1, isim = 1 8077 8116 D type hexa usim = 1, isim = 1 pcscf_v4 : num = 2, protocol_type = 0x21, port_num = 0, addr = 10.56.5.85 8088 1223 D temp sim_invalid = 0 8099 1223 XX is_ems_support = 1 #88 8099 1224 XX pdn_act_ind->pcscf_discovery_flag = 1 ind->signaling_flag = 1 some text here plmn = 405872 DefaultStatusBarPlmnPlugin: into updateCarrierLabel ipv6 = 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161 get_ipv6_prefix,temp ipv4 = 10.167.185.101 _send_ipv4_notify info.is_ems_support = 1 act_ind->emergency_indication = 1 access_rat_type = 0 transaction_id = 2, rat_type = 0

        My output should be like these for above data Into excel format isim = 1 usim = 1 sim_invalid = 0 pcscf_discovery_flag 1 signaling_flag 1 ran_type 0 emergency_ind 1 rat pcscf_v4 10.56.5.85 pcscf_v6 plmn 405872 is_ems_support 1 ipv4 10.167.185.101 ipv6 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161

        Issue - I am not able to get the corresponding lines searched matching keywords so I can pull out the variables value from these lines and put back into excel corresponding to these keywords e.g. x =5 (x is variable and 5 is the value to be picked from a line containing x) Can you please help ?