473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Spreadsheet::WriteExcel - Writing into existing file

hi,

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...

Thanks

Rasmia
Aug 13 '07 #1
5 11031
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.

Andy
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;
  7.  
  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");
  16.  
  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');
  23.  
  24. $worksheet->activate();
  25. $worksheet->write(0,0,"Name",$excel_look);
  26. $worksheet->write(0,1,"Emp Id",$excel_look);
  27.  
Please suggest me what needs to change...

Thanks a lot

Rasmita
Aug 14 '07 #3
miller
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
Hi,

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...

Thanks
Rasmita
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. }
  9.  
  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. }
  17.  
  18. # ******** add your code here ************
  19.  
  20. if ($Exists eq "true") {
  21.     $Bookook->Save();
  22. } else{
  23.     $Book->SaveAs("$filepath") or die $!;
  24. }
  25.  
Hope this helps.

KARTHIK
Aug 15 '07 #6

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

Similar topics

0
by: Dorthe Luebbert | last post by:
Hi, there is a new(er) version of John McNammara's Excel package for Perl: http://homepage.eircom.net/~jmcnamara/perl/prerel/Spreadsheet-WriteExcel-0.49.7.tar.gz The package writes Excel97...
2
by: Fabio | last post by:
Hello, there's a module called Spreadsheet::WriteExcel. It allows me to create a new worksheet and edit its cells: my $workbook = Spreadsheet::WriteExcel->new('my.xls'); my $worksheet =...
4
by: tito | last post by:
I am using Active Perl for running perl programs.I am finding difficulty in installing Spreadsheet::WriteExcel,Spreadsheet:ParseExcel to the machine for writing a program which will retrieve data...
3
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any...
1
by: vijaymohan | last post by:
Hi ..I am very new to perl..can some one help me with this script pls.. I am Querying database and writing data to excel.. Here is my script: #!/usr/bin/perl -w use strict; use DBI;
5
by: bvithya | last post by:
Hi Gurus, I am in need of your guidance. I have installed Perl5.8.8 on my server running with SunOS 5.8 and then I installed Spreadsheet::WriteExcel perl module. It has been installed...
8
by: Perl Beginner | last post by:
I am using Win32. I have created an excel spreadsheet, formatted the columns and rows, and would like to write to the cells…all of this using Spreadsheet::WriteExcel. My issue is, my script is very...
2
by: vijayarl | last post by:
Hi Everyone, Am trying to collate the individual xls files into a single xls file.i have written this code. use strict; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; use...
7
by: somsub | last post by:
Hi, When I tried to open excel sheet created by below code with MSexcel it showing "Unable to read file " error . use Spreadsheet::WriteExcel; $workbook =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.