Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Using Spreadsheet:WriteExcel or whatever else I need

by bennierounder (Sexton)
on Oct 26, 2011 at 10:48 UTC ( #933858=perlquestion: print w/replies, xml ) Need Help??
bennierounder has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys

I'm wondering how i can insert a word into the top of an excel file using perl without messing with the format. I want to add a row at the top of the file and insert a word in the first row first column keeping same format, having dramas.

I have created a new file with the word i want in 0,0 then i want the other document to copy itself under this word. basically I just want everything to be a row lower than it is in the same format and then insert a word into the first row first column for encryption purposes. Can anyone help?

if ($WE_NEED_TO_DO_ENCRYPTION) { if ($ext =~ /XLS/i) { # open a new excel file insert the word 'encryted' on the 1st ro +w, 1st column. my $workbook = Spreadsheet::WriteExcel->new($report_type . '_' +. $time . $ext); my $worksheet = $workbook->add_worksheet(); $worksheet->write(0, 0, 'encrypted'); # now copy report file into the new xsl file. # THIS IS WHERE I AM STUCK I NEED TO PUT THE REST OF ANOTHER FIL +E HERE IN THE SAME FORMAT

Replies are listed 'Best First'.
Re: Using Spreadsheet:WriteExcel or whatever else I need
by RMGir (Prior) on Oct 26, 2011 at 11:44 UTC
    I can't help with your specific issue, but just yesterday I read this which points out that Spreadsheet::WriteExcel has been superseded by Excel::Write::XLSX.

    I suggest starting with the new module and seeing if it implements any new features which might help...


      Thanks it seems a good module, however it doesn't quite cater for my needs at this present time

      Be nice if John McNamara was here to check this lol

Re: Using Spreadsheet:WriteExcel or whatever else I need
by jmcnamara (Monsignor) on Oct 26, 2011 at 13:30 UTC

    There is a Spreadsheet::ParseExcel::SaveParser module that allows you to re-write an Excel file but it doesn't always work very well and in this particular case it can't be used to shift the rows down.

    So, you will probably have to use Spreadsheet::ParseExcel to read the old file and then use Spreadsheet::WriteExcel to write the new one with the rows shifted down.

    The feasibility of that depends on the complexity of the input file.

Re: Using Spreadsheet:WriteExcel or whatever else I need
by Lotus1 (Curate) on Oct 26, 2011 at 16:02 UTC
Re: Using Spreadsheet:WriteExcel or whatever else I need
by stefbv (Curate) on Oct 26, 2011 at 17:21 UTC

    The following might be a solution in the (unlikely) situation when the file is in the "ODF" format. Only tested with a file created with LibreOffice.

    It uses the ODF::lpOD module developed by Jean-Marie Gouarné and requires at least Perl v5.10.

    use strict; use warnings; use 5.010_000; use ODF::lpOD; my $file = shift; my $doc = odf_document->get($file); my $table = $doc->get_body->get_table(); $table->read_optimize(TRUE); $table->add_row(number => 1, before => 0, empty => 'true'); $table->get_cell(0,0)->set_text("Bonjour le monde !"); $doc->save();

    Regards, Stefan

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://933858]
Approved by planetscape
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-06-19 12:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.