in reply to OpenOffice::OODoc. Slow access to a cell content with getCellValue

You could try using the getTableText method to fill an array.

#!/usr/bin/perl use strict; use OpenOffice::OODoc; use Data::Dump 'pp'; my $doc = odfDocument(file => "myspreadsheet.ods"); open (my $out, '>', "outfile.txt") or die $!; foreach my $sheetno (0...$doc->getTableList-1){ my $table = $doc->getTable($sheetno,'normalize'); my ($rows,$cols) = $doc->getTableSize($table); my @text = $doc->getTableText($table); #pp @text; print "Sheet=$sheetno rows=$rows cols=$cols\n"; foreach my $rowno (0...$rows-1){ foreach my $colno (0...$cols-1){ my $value = $text[$rowno][$colno]; next if $value eq ''; print $out $value,"\n" } print $out "\n"; } };
poj

Replies are listed 'Best First'.
Re^2: OpenOffice::OODoc. Slow access to a cell content with getCellValue
by pvaldes (Chaplain) on Jun 01, 2016 at 22:33 UTC
    Much faster Poj, only 11 minutes running (against "infinite minutes"), but the outfile.txt was totally empty after this time. Something is wrong :-(

      I used this to create a simple test file

      #!/usr/bin/perl use strict; use OpenOffice::OODoc; my $doc = odfDocument( file => 'testspreadsheet.ods', create => 'spreadsheet'); $doc->expandTable(0,5,10); for my $r (0..4){ for my $c (0..9){ $doc->cellValue(0,$r,$c,"text at ".chr(65+$c).($r+1)); } } $doc->save;
      poj

      Update: It seems that there was problem with the memory when I run your script, Poj. This problem could or could not be related with the perl job.

      I'm running again the script with the -d option. When It hits the line

       my $table = $doc->getTable($sheetno,'normalize');

      The perl script uses the 99-100% of CPU and the 10% of memory. After some minutes the memory consume raises to 81-83% until finally the computer frozens and the process is automatically killed without finishing the job. This takes 6-11 min and explains why outfile.txt is empty. It seems that my spreadsheet file is a hard nut to open. I wonder why.