biswanath_c has asked for the wisdom of the Perl Monks concerning the following question:


Hi

I am writing data into excel spreadhseet using the Spreadsheet::WriteExcel module. I noticed that looks like the API $sheet->write($row, $col, $data) does not write data into the spreadsheet immediately; instead PERL stores all the data in memory and only flushes them into the spreadsheet during probably the invocation of the $workbook->close API or the end of the program. Because of this, after sometime, my program crashes giving the "Out of Memory!" error.

Can anyone help me resolve this issue? Is it possible to flush the data into the spreadsheet whenever required?"


Thanks

Biswanath
  • Comment on Out of Memory Error while Writing to Spreadsheets in PERL...

Replies are listed 'Best First'.
Re: Out of Memory Error while Writing to Spreadsheets in PERL...
by kennethk (Abbot) on May 11, 2010 at 18:46 UTC
    From Spreadsheet::WriteExcel:

    An Excel file is a binary file within a binary file. It contains several interlinked checksums and changing even one byte can cause it to become corrupted.

    As such you cannot simply append or update an Excel file. The only way to achieve this is to read the entire file into memory, make the required changes or additions and then write the file out again.

    This would suggest the easy answer to your question is no. Are you sure that the memory problems are coming from the module in question (Devel::Monitor)? Can you split your task into multiple files? Can you buy more memory or run on a machine with more?

    As a side note, the program is 'perl' and the language is 'Perl'. There is no 'PERL'.

Re: Out of Memory Error while Writing to Spreadsheets in PERL...
by CountZero (Bishop) on May 11, 2010 at 21:44 UTC
    Alternatively you can save your data in comma- or tab-separated values format and use Excel to read that file and save it in its native format.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Out of Memory Error while Writing to Spreadsheets in PERL...
by ww (Archbishop) on May 11, 2010 at 21:24 UTC