Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Adding new workbook to existing excel

by Shaveta_Chawla (Sexton)
on Jan 29, 2013 at 10:41 UTC ( [id://1015844]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I have created an excel sheet using perl and i am writing the data into that excel file like this
use Spreadsheet::WriteExcel; my $FileName = "/home/Desktop/ABC/report.xls"; my $workbook = Spreadsheet::WriteExcel->new($FileName); my $worksheet1 = $workbook->add_worksheet('report1'); $worksheet1->write($i, 0, $url); $worksheet1->write($i, 1, $title);
Now in the second run i want to create a new worksheet 'report2' to the existing file report.xls. but every time i do that my earlier worksheet is deleted. How can i do that?

Replies are listed 'Best First'.
Re: Adding new workbook to existing excel
by LanX (Saint) on Jan 29, 2013 at 10:55 UTC
    according to Spreadsheet::WriteExcel new() creates a new file, quote: "The following example creates a new Excel file based on a filename:"

    And I can't find how to append to an existing file.

    2 possible workarounds:

  • hold the data separately until you finalize he hole sheet at once.

  • use Spreadsheet::ParseExcel to read the old data and to rebuild the new spreadsheet

    Cheers Rolf

Re: Adding new worksheet to existing Excel workbook
by Ratazong (Monsignor) on Jan 29, 2013 at 11:35 UTC

    If you are in a Windows environment, you could use Win32::OLE to work with Excel. Adding a new worksheet can be done like this:

    #___ ADD NEW WORKSHEET $workbook -> Worksheets -> Add({After => $workbook -> Worksheets($work +book -> Worksheets -> {Count})});
    note: The line above has been taken from this great example, which you surely want to check out.

    HTH, Rata

      I definitely concur with this.   Fire up the Excel application in this manner, and tell it what you want it to do.

      It took Microsoft a bunch of years to finally get OLE “really right,” and for computers to grow-up enough to easily handle it ... but ... they did and they did.   Do it that way.

Re: Adding new workbook to existing excel
by vinoth.ree (Monsignor) on Jan 29, 2013 at 12:28 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1015844]
Approved by fisher
Front-paged by fisher
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-19 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found