Perl : blank lines are displayed in the output after deleting few rows from excel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl : blank lines are displayed in the output after deleting few rows from excel
# 1  
Old 08-02-2012
Perl : blank lines are displayed in the output after deleting few rows from excel

I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations.
In this process, I first defined 10 records in excel sheet and executed the below code.
In the first run it is OK. But after deleting last few rows in excel sheet and then running, blank lines are displayed at the end.

Code:
#!C:\perl\bin –w
    use strict;
    use Spreadsheet::ParseExcel;
    my $FileName = "C:/pro1/birthdays.xls";
    my $parser   = Spreadsheet::ParseExcel->new();
    my $workbook = $parser->parse($FileName);
    die $parser->error(), ".\n" if ( !defined $workbook );
    # Following block is used to Iterate through all worksheets
    # in the workbook and print the worksheet content 
    for my $worksheet ( $workbook->worksheets() ) {
        # Find out the worksheet ranges
        my ( $row_min, $row_max ) = $worksheet->row_range();
        my ( $col_min, $col_max ) = $worksheet->col_range();
        for my $row ( $row_min .. $row_max ) {
            for my $col ( $col_min .. $col_max ) {
                # Return the cell object at $row and $col
                my $cell = $worksheet->get_cell( $row, $col );
                next unless $cell;
                print "Row, Col    = ($row, $col)\n";
                print "Value       = ", $cell->value(),       "\n";
            }
        }
    }

---------- Post updated at 06:46 AM ---------- Previous update was at 06:33 AM ----------

Its done..

applied if condition to check the string whether null or not

Code:
$temp = $cell->value();
                if ($temp ne "")
                {
                print "Value       = ", $cell->value(),       "\n";
                }


Last edited by Scott; 08-02-2012 at 09:14 AM.. Reason: Use code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting columns of text to rows, with blank lines

I've spent the past hour trying different things and googling for this solution and cannot find the answer. Found variations of this, but not this exact thing. I have the following text, which is the output from our mainframe. Each field is on a separate line, with a blank line between each... (7 Replies)
Discussion started by: lupin..the..3rd
7 Replies

2. Shell Programming and Scripting

Need to remove a selection of rows separated by blank lines

hello, here is an example: 9.07 9.05 0.00 2.28 0.00 0.08 1.93 3.62 10.97 12.03 12.03 0.00 2.73 0.00 0.07 (3 Replies)
Discussion started by: Baron1
3 Replies

3. Shell Programming and Scripting

Perl : Deleting the records in the excel sheet

I have a excel sheet with contains the records as below.. also uploaded the input excelsheet and the output excel sheet(expected output). 322mpls32.net.xyz.comBW: 44.0 M Hrly Avg (IN /... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Shell Programming and Scripting

perl - output not being displayed

Hi All I have the following code sub pall_nvrm { my $cmd = `pall -w "/u/ab/scripts/dev/nvrmerros/nvrmpaller"`; print $cmd; } if i run pall -w "/u/ab/scripts/dev/nvrmerros/nvrmpaller" in a shell i get this sort of out put eagley: boxted: cadle: eabost: hales: (3 Replies)
Discussion started by: ab52
3 Replies

5. Shell Programming and Scripting

deleting blank lines ONLY at the end of the file

Hi Guys, I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me. I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
Discussion started by: aoussenko
5 Replies

6. Shell Programming and Scripting

using libraries with Perl..getting blank output

Good morning!! Im trying to create a script that should get a list of numbers from the user (using STDIN or a list of arguments), and call my library function. My script: #!use/bin/perl require 'my-lib.pl'; @userArray = <STDIN>; while() { chomp; last if ! /\d/;... (1 Reply)
Discussion started by: bigben1220
1 Replies

7. Shell Programming and Scripting

Count uncommented, blank and source lines in perl

Hi friends, I am working on a perl script to count the commented lines, blank lines and source lines separately. Let me know if you have one. For example i have a file containing the lines: /** * SOURCE CODE */ public class SessionConstants { /** * Code for Session created */... (4 Replies)
Discussion started by: nmattam
4 Replies

8. Shell Programming and Scripting

deleting last n lines from a output

Friends, I am executing this command in solaris sar -d 3 3 | awk 'NR > 2 { if ($1 !~ /,.+/) print }' | egrep -v "nfs|device" . Now i want to delete the last two lines of my output as they are records of average which i don't want. can some one pls give me some idea on how to proceed. (7 Replies)
Discussion started by: achak01
7 Replies

9. Shell Programming and Scripting

PERL: removing blank lines from multiple files

Hi Guru's , I have a whole bunch of files in /var/tmp that i need to strip any blank lines from, so ive written the following script to identify the lines (which works perfectly).. but i wanted to know, how can I actually strip the identified lines from the actual source files ?? my... (11 Replies)
Discussion started by: hcclnoodles
11 Replies

10. Shell Programming and Scripting

deleting particular lines and moving a line up using perl/sed

Hi, I need convert a dump file in the following format : (please note that line numbers are provided for easy look) Original file: 1 2007-10-2482.90 No trade 0 0.00 100000.00 2 100000.00 3 0.00 4 HOLD 5 2007-10-2589.75 Bought 1114 1114 100000.00 0.00 ... (5 Replies)
Discussion started by: sabyasm
5 Replies
Login or Register to Ask a Question