Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Adding new workbook to existing excel

by Shaveta_Chawla (Acolyte)
on Jan 29, 2013 at 10:41 UTC ( #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?

Comment on Adding new workbook to existing excel
Download Code
Replies are listed 'Best First'.
Re: Adding new workbook to existing excel
by LanX (Canon) 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 (Prior) 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 (Prior) on Jan 29, 2013 at 12:28 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2015-07-07 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls