469,306 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Spreadsheet::WriteExcel - Writing into existing file


I am very new to perl.I have written a perl script which is writing data into an excel file.The problem is that it is creating one new excel file while executing but my need id to write into an existing .xls file.
currently I am using:
my $workbook = Spreadsheet::WriteExcel::Big->new("file.xls");
for that which method Should I use??
can anyone please help me...


Aug 13 '07 #1
5 10624
Have you tried using Spreadsheet::ParseExcel to read out the data, and then use WriteExcel to put it all back into another new file?

It's a bit of a drag, but the only other way I know how to do it is to use Win32::OLE which is (IMHO) much more awkward.

Aug 13 '07 #2
Thank You Andy..Due to our internal system problem I hav not tried Spreadsheet::ParseExcel .I am writing the perl script which will run on the Solaries environment.Will Win32::OLE work there???

My code is...

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use File::Copy;
  3. use File::Path;
  4. use File::Basename;
  5. use Spreadsheet::WriteExcel::Big;
  6. use Data::Dumper;
  8. my $wrksheet = "Details";
  9. my $sheet_name;
  10. my $excel_look;
  11. my $v_name = "Shilpy";
  12. my $v_empid= 194050;
  13. #my $sFile = "test1.xls";
  14. my $workbook = Spreadsheet::WriteExcel::Big->new("file.xls");
  15. my $worksheet = $workbook->add_worksheet("Details");
  17. #$sheet_name = $excel_sheet->addworksheet($wrksheet);
  18. $excel_look = $workbook->addformat();
  19. $excel_look->set_size(10);
  20. $excel_look->set_color('black');
  21. $excel_look->set_align('center');
  22. $excel_look->set_font('Arial');
  24. $worksheet->activate();
  25. $worksheet->write(0,0,"Name",$excel_look);
  26. $worksheet->write(0,1,"Emp Id",$excel_look);
Please suggest me what needs to change...

Thanks a lot

Aug 14 '07 #3
1,089 Expert 1GB
As Andy points out, it is not directly possible to edit an exiting excel spreadsheet. Instead you must first parse and then create a new excel sheet.

cpan Spreadsheet::ParseExcel
cpan Spreadsheet::WriteExcel

- Miller
Aug 14 '07 #4

Thanks Miller.I hav gone through the given links,but not get any satisfactory result.My query is when ever I will execute the script it will create the new file and erase the previous data,this is not my requirement.I want to append new data,when I will execute the script 2nd time.

Please help me, its very very urgent...

Aug 14 '07 #5
Hi Rasmita,

I recently did something quite similar. The script adds tabs to an existing excel file each time it is run and saves the file. I did it using Win32::OLE. You could do something like the below:

Expand|Select|Wrap|Line Numbers
  1. $filepath = 'file.xls';
  2. if (-e $filepath) {
  3.     $Book = $Excel->Workbooks->Open($filepath);
  4.     $Exists = "true";
  5. } else {
  6.     $Book = $Excel->Workbooks->Add();
  7.     $Exists = "false";
  8. }
  10. if ($Exists eq "true") {
  11.     $previousSheet = $Book->ActiveSheet;
  12.     $currentSheet = $Book->Worksheets->Add();
  13.     $Book->ActiveSheet->{Name} = "new tab";
  14. } else {
  15.     $previousSheet = 0;
  16. }
  18. # ******** add your code here ************
  20. if ($Exists eq "true") {
  21.     $Bookook->Save();
  22. } else{
  23.     $Book->SaveAs("$filepath") or die $!;
  24. }
Hope this helps.

Aug 15 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Dorthe Luebbert | last post: by
2 posts views Thread by Fabio | last post: by
3 posts views Thread by toffee | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.