Visit Our UNIX and Linux User Community


Perl script to extract second column from a xls


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script to extract second column from a xls
# 1  
Old 08-17-2010
Perl script to extract second column from a xls

Can Anyone tell me how to extract the second column of a xls sheet
And compare the content of each row of the column with a .h file.

xls sheet is having only one spreadsheet.
# 2  
Old 08-17-2010
Try out the Win32::OLE Perl module at CPAN.

Win32::OLE - search.cpan.org

Values in the 2nd column would be: $sheet->Cells($row,2)->{Value}

tyler_durden
# 3  
Old 08-18-2010
Hello All,

Code:
my $Book = $Excel->Workbooks->Open("u:/file_list.xls"); 
my $Book1 = $Excel->Workbooks->Open("u:/output.xls");

my $Sheet = $Book->Worksheets(1);
my $Sheet1 = $Book1->Worksheets(1);


$Book(second column) content looks like this:

Code:
DIR_source\CSD\CSD_SDdata.c

$Book1 (first column)content looks like this:

Code:
M:\srath_view\DIR_source\CSD\CSD_SDdata.c@@\main\ucm_source\600_int\a380_wipro_600_int\a380_std_600_cleanup_int\2

Take the content of each row of second column and compare it with each row of the first column of $Book1:


Code:
foreach my $row (1..200)
{ 
  my $var = $Sheet->Cells($row,2)->{'Value'};
  findl($var);
}

sub findl{
  my ($exp)= @_;   # $exp = expression to find
  my $val;
  my $line;
  my $cnt=0;
  for($cnt=1;$cnt<=65536;$cnt++){
    $val = $Excel->Cells($cnt,$1)->{'Value'};
    if ((defined $val) && (index($val,$exp) != -1)){
      $line =$cnt if (!defined $line);
      last;
    }
   }
  return ($line);  
}

Now i got the line on which
Code:
DIR_source\CSD\CSD_SDdata.c

exist.

Now i want to cut the content

Code:
\main\ucm_source\600_int\a380_wipro_600_int\a380_std_600_cleanup_int\2

where my match is done....

It means i want to cut the content after the \main till the end......

Hope you got my question

Previous Thread | Next Thread
Test Your Knowledge in Computers #515
Difficulty: Easy
A variable's type (or data type) is the characterization of the data that it represents.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing xml from excel sheet .xls using perl script

Hi all. I am working on the below requirement of generating .xml file from .xls file which i have , can someone please help me or in writing the perl script for the same: The xls file format is as below which has two columns and number of rows are not fixed: Fixlet Name ... (12 Replies)
Discussion started by: omkar.jadhav
12 Replies

2. Shell Programming and Scripting

Perl - Extract first column from file

Hi, I want to extract first column from a file and redirect the output to another file in perl. I am able to do this from command line by executing below commands. perl -anle 'print $F' Input.dat > Output.dat perl -ne '@F = split("\t", $_); print "$F\n";' Input.dat > Output.dat perl -anE... (7 Replies)
Discussion started by: Neethu
7 Replies

3. Shell Programming and Scripting

Perl script to convert xlsx to xls file

Hi I am trying one perl script to convert xlsx to xls file but could not able to get all the rows and columns in the xls file . This scriptFILE is basically to convert XLSX to CSV .. I am tweaking the script to convert XLSX to XLS file also #######################FILE... (3 Replies)
Discussion started by: kshitij
3 Replies

4. Shell Programming and Scripting

Perl regexp to extract first and second column

Hi, I am trying with the below Perl one-liner using regular expression to extract the first and second column of a text file: perl -p -e "s/\s*(\w+).*/$1/" perl -p -e "s/\s*.+\s(.+)\s*/$1\n/" whereas the text file's data looks like: Error: terminated 2233 Warning: reboot 3434 Warning:... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

Perl script to Convert XLSX or XLS files to CSV file

Hi All, I've got in a situation where I need to convert .xlsx or .xls formatted files into simple text file or .csv file. I've found many options but doing this using PERL script is the best way I believe.I'm in AIX box. Perl code should have 2 params while running. i.e perl... (1 Reply)
Discussion started by: manab86
1 Replies

6. Shell Programming and Scripting

Perl script to get info from specific rows & columns (.xls file)

Hi all, I want to read some specific rows & columns in the .xls file with my script to get the data to be manipulated. Now, I can read the .xls file correctly & i can go to the specific sheet that I want but i have a problem to specify the specific rows & columns. I mean, I want to get the info... (0 Replies)
Discussion started by: Yohannita
0 Replies

7. Shell Programming and Scripting

Extract first column from second line in perl

Hello Gurus I have a source file which has the first line as header and the rest are the records I need to extract the first column from the second line to extract a value I/P ... (7 Replies)
Discussion started by: Pratik4891
7 Replies

8. Shell Programming and Scripting

Reading a column from xls file using perl

Hi Everyone! I have a problem in reading a specific column from .xls file using perl language and then manipulating on given criteria. Detailed Description of the problem:: I have one .xls file, in which i have to populate two columns based on Period_date column which is in same file. My... (1 Reply)
Discussion started by: kvth
1 Replies

9. Shell Programming and Scripting

extract values from column with Perl

Hi everybody I have some problems with PERL programming. I have a file with two columns, both with numeric values. I have to extract the values > 50 from the 2nd columns and sum them among them. The I have to sum the respective values in the first column on the same line and, at the end, I... (6 Replies)
Discussion started by: m_elena
6 Replies

10. Shell Programming and Scripting

How to extract output from a script to .xls file

Hi, I am running a script, the output of which is needed to be filled in .xls file. I am doing this manually now, i mean I am writing the output of the script to Excel file manually. How to redirect the output of the script to .xls file? Please help me out!!! Thanks much, Scriptlearner. (6 Replies)
Discussion started by: scriptlearner
6 Replies

Featured Tech Videos