473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Spreadsheet::Wr iteExcel - Writing into existing file

3 New Member
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::Wr iteExcel::Big->new("file.xls" );
for that which method Should I use??
can anyone please help me...

Thanks

Rasmia
Aug 13 '07 #1
5 11065
AndyHunt
4 New Member
Have you tried using Spreadsheet::Pa rseExcel 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
rasmitasah25
3 New Member
Thank You Andy..Due to our internal system problem I hav not tried Spreadsheet::Pa rseExcel .I am writing the perl script which will run on the Solaries environment.Wil l 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 Recognized Expert Top Contributor
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::Pa rseExcel
cpan Spreadsheet::Wr iteExcel

- Miller
Aug 14 '07 #4
rasmitasah25
3 New Member
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
karthikkotha
2 New Member
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
2917
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 instead of Excel5, it has e.g. no longer the 255 char's limit for one cell etc. See:
2
7377
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 = $workbook->addworksheet(); $worksheet -> write('A2', 222); But how can I put some values into the cells of an existing worksheet?
4
14704
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 from an Excel Sheet. Can anyone explain me the steps to install Spreadsheet::WriteExcel,Spreadsheet:ParseExcel in Windows machine.
3
16009
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 links or pointers? i've already tried google - but all i get is ActiveX methods which work in a very few cases.
1
2538
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
2833
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 successfully. Howver when I try to run a command to check whether it emails an excel sheet or not, it showed me the below. # /home/oracle8/oradba/admin/utils/sqlplus2xls/sqlplus2xls.pl ERROR (Missing Parameter): <config_file> not specified!
8
9429
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 vast with a lot of subroutines, but I need the excel spreadsheet created in the main subroutine becasue this is where the data is that i want to capture. So if I create and format the spreadsheet within the main subroutine, and as it loops through,...
2
1830
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 Spreadsheet::WriteExcel::Big; my $consol_rows=0;
7
3783
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 = Spreadsheet::WriteExcel->new("sm2.xls"); I am using winxp OS and MS excel 2003 ....
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.