I'm playing with the module OpenOffice and trying to extract some info from a spreadsheet to a text file. This is my program so far:

#!/usr/bin/perl use strict; use warnings; use OpenOffice::OODoc; ## module version 2.125.3, from Debian Perl Group, installed with: ## apt install libopenoffice-oodoc-perl open (my $out, '>', "outfile.txt") or die $!; my $file = ooFile("myspreadsheet.ods"); my $content = odfText(file => $file, part => 'content') or die $!; # Note: "odfText can be used in place of ooDocument() # if the calling application is only text-focused # We aren't interested in formats or styles. Perldoc" ## Write to a file the content of the non empty cells ## in the interval B1:G2001 from "sheet2" to "sheet9" ## in the .ods libreoffice spreadsheet. foreach my $sheet (1...8){ foreach my $row (0...2000){ foreach my $col (1...6){ my $value = $content->getCellValue($sheet,$row,$col); next if $value eq ""; # next if cell is empty next if $value eq "Don't keep this"; # or if match some pattern print $out $value,"\n"} # print cell content to outfile print $out "\n";} # and a newline at the end of each row print "okay, next sheet\n-------\n"; }; close $out;

When I run the program it take hours to finish. Much more slow than doing it directly with the mouse. I have also a warning message about a undefined "" value (maybe the problem is that $value is not of type string and need to be converted each time first?).

I would appreciate if you can take a look to this draft and suggest how to make it faster, or maybe point to any bug or possible memory leak. Thank you very much.


In reply to OpenOffice::OODoc. Slow access to a cell content with getCellValue by pvaldes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.