Sponsored Content
Top Forums Shell Programming and Scripting Perl : blank lines are displayed in the output after deleting few rows from excel Post 302680683 by giridhar276 on Thursday 2nd of August 2012 07:46:51 AM
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...
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Excel::Template::Container::Worksheet(3pm)		User Contributed Perl Documentation		Excel::Template::Container::Worksheet(3pm)

NAME
Excel::Template::Container::Worksheet - Excel::Template::Container::Worksheet PURPOSE
To provide a new worksheet. NODE NAME
WORKSHEET INHERITANCE
Excel::Template::Container ATTRIBUTES
o NAME This is the name of the worksheet to be added. o PROTECT If the attribute exists, it will mark the worksheet as being protected. Whatever value is set will be used as the password. This activates the HIDDEN and LOCKED nodes. o KEEP_LEADING_ZEROS This will change the behavior of the worksheet to preserve leading zeros. o HIDE_GRIDLINE his method is used to hide the gridlines on the screen and printed page. Gridlines are the lines that divide the cells on a worksheet. Screen and printed gridlines are turned on by default in an Excel worksheet. If you have defined your own cell borders you may wish to hide the default gridlines. $worksheet->hide_gridlines(); The following values of $option are valid: 0 : Don't hide gridlines 1 : Hide printed gridlines only 2 : Hide screen and printed gridlines If you don't supply an argument or use undef the default option is 1, i.e. only the printed gridlines are hidden. o LANDSCAPE This will set the worksheet's orientation to landscape. o PORTRAIT This will set the worksheet's orientation to portrait. While this is the default, it's useful to override the default at times. For example, in the following situation: <workbook landscape="1"> <worksheet> ... </worksheet <worksheet portrait="1"> ... </worksheet <worksheet> ... </worksheet </workbook> In that example, the first and third worksheets will be landscape (inheriting it from the workbook node), but the second worksheet will be portrait. o AUTOFILTER With these attribute, you can add the autofilter to a worksheet. An autofilter is a way of adding drop down lists to the headers of a 2D range of worksheet data. This is turn allow users to filter the data based on simple criteria so that some data is shown and some is hidden. Example to add an autofilter to a worksheet: <workbook> <worksheet autofilter='A1:D11' /> <worksheet autofilter='0, 0, 10, 3' /> </workbook> CHILDREN
None EFFECTS
None DEPENDENCIES
None USAGE
<worksheet name="My Taxes"> ... Children here </worksheet> In the above example, the children will be executed in the context of the "My Taxes" worksheet. AUTHOR
Rob Kinyon (rob.kinyon@gmail.com) SEE ALSO
ROW, CELL, FORMULA perl v5.14.2 2010-06-17 Excel::Template::Container::Worksheet(3pm)
All times are GMT -4. The time now is 02:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy