Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Deleting entire row and column

by harishnv (Sexton)
on Mar 09, 2018 at 06:48 UTC ( [id://1210544]=note: print w/replies, xml ) Need Help??


in reply to Re: Deleting entire row and column
in thread Deleting entire row and column

Output file Reg number output 2. Correct 4. Wrong Input file Blank box Blank box Reg number. Output 2. Correct 4. Wrong

The input file is starting from cell (2,2) But I want to start from (1,1) cell. How to delete the first row and column entirely in excel file.

Replies are listed 'Best First'.
Re^3: Deleting entire row and column
by Happy-the-monk (Canon) on Mar 09, 2018 at 07:57 UTC

    In your programme, create a new worksheet and copy the current data into it as follows:

    Start reading at 1,1 in the original worksheet...
    ...only subtract 1 from both coordinates when you write to the new one, so you achieve the goal.

    After the new worksheet is done writing, delete the original,
    then rename the new one with the name of the original one.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

      use strict; use Spreadsheet::ParseExcel; use Data::Dumper; use Spreadsheet::WriteExcel; my $val=0; my $last_col; my $col=0; my $row=0; my @req_sfr_array; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('formatting.xls'); my $row1; my $col1; if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $workbook = Spreadsheet::WriteExcel->new("perl.xls"); $worksheet = $workbook->addworksheet(); foreach my $worksheet ( $workbook->worksheets() ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); print DEBUG_LOG "PARSING WORKSHEET:", $worksheet->get_name(), "\n" +; print "\n"; print "ROW_MIN = $row_min, ROW_MAX = $row_max\n"; print "COL_MIN = $col_min, COL_MAX = $col_max\n"; print "\n"; for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); next unless ($cell);; next unless ($cell->value() =~ /\S+/);; my $val = 0; print "Row, Col = ($row, $col)\n"; print "Value = ", $cell->value(), "\n"; print "\n"; $val = $cell->value(); } if($val eq "Register") { if($row==0 and $col!=0) { $row1=$row; $col1=$col-$col; } elsif($row!=0 and $col==0) { $row1=$row-$row; $col1=$col; } else { $col1=$col-$col; $row1=$row-$row; } $worksheet->write($row1, $col1, "$val"); } else { // i'm not getting what logic i should write to shift the cell + after encountering first cell and shifting } } }

      not able to figure out what to write next, help me out!

        $worksheet->write($row1, $col1, "$val");

        Basically, you will need a new worksheet (as said above) to write into for any worksheet you want to rewrite.

        So the code for writing will be: $new_worksheet->write($row -1, $col -1, "$val");

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Re^3: Deleting entire row and column
by choroba (Cardinal) on Mar 09, 2018 at 07:55 UTC
    XLS or XLSX? What modules do you already use to process the Excel file?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      XLS file

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210544]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found