#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $filename = $ARGV[0] or die "Parsing error: must specify filename.\n"; my $workbook = $parser->parse( $filename ); die "Parsing error: ", $parser->error(), ".\n" if !defined $workbook; # Select a particular worksheet. my $worksheet = $workbook->worksheet( 0 ); # Get the worksheet cell range. my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); # Store the individual column maxima. my @col_maxes; for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); if ( defined $cell && $cell->value() ne '' ) { $col_maxes[$col] = $row; } } } # The rows and columns are zero indexed and columns that don't contain # data and thus don't have a maximum value will be undef. The following # prints out the data in Excel 1-indexed style. my $col_name = 'A'; for my $max ( @col_maxes ) { if ( defined $max ) { $max = $max + 1; } else { $max = 0; } print "Column '$col_name' max row = $max\n"; $col_name++; } __END__ For a spreadsheet like this: ________ _| Sheet1 |__________________________________________________ |_____________________________________________________________| | || | | | | || A | B | C | |_________||________________|________________|________________| | 1 || Foo | | | |_________||________________|________________|________________| | 2 || | | Foo | |_________||________________|________________|________________| | 3 || Foo | | | |_________||________________|________________|________________| | 4 || | | Foo | |_________||________________|________________|________________| Prints this: Columm 'A' max row = 3 Columm 'B' max row = 0 Columm 'C' max row = 4