N
N
Nicholas2012-03-12 14:45:17
Perl
Nicholas, 2012-03-12 14:45:17

Parsing XLSX in Perl

Good afternoon!

I'm looking for how to pull out a cell comment in an XLS(X) sheet in Perl. Google is rummaged)
Who knows - please advise.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2012-03-12
@Neuronix

Found this, maybe it will help someone:

######################################
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use strict;

my $xl = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application');
die "Cannot start Excel" unless $xl;

my $workbook=$xl-> Workbooks->Open('C:\\temp\\book1.xls');
my $worksheet=$workbook->Worksheets('Sheet1');

my $LastRow = $worksheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};

my $LastCol = $worksheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};

print "Number of used rows: $LastRow\n";
print "Number of used cols: $LastCol\n";

my $lnRow=1;
my $lnCol=1;

while ($lnRow <= $LastRow) {
$lnCol = 1 if ($lnCol > $LastCol);
my $notes = $worksheet->Cells($lnRow,$lnCol)->{NoteText};
print $notes,"\n" if ($notes);
$lnRow++ if $lnCol == 1;
$lnCol++;
}

$xl->Quit;
__END__
###############################

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question