473,587 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to append excel sheet using win32::OLE

170 New Member
hi all,

i've got the following program that needs yr help:
Expand|Select|Wrap|Line Numbers
  1. use Win32::OLE;
  3.         # use existing instance if Excel is already running
  4.         eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
  5.         die "Excel not installed" if $@;
  6.         unless (defined $ex) {
  7.             $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
  8.                     or die "Oops, cannot start Excel";
  9.         }
  12.         # get a new workbook
  13.         $book = $ex->Workbooks->Add;
  14.     $sheet = $book->Worksheets(1);
  16.         # write a 2 rows by 3 columns range
  17.         $sheet->Range("A1:J2")->{Value} = [['Date','Total (IN)','Succ (IN)','Pk (IN)/Hrs','Pk (OUT)/Hrs','Peak Hour','Total (OUT)','Succ (OUT)','MO(IN)','MO(OUT)'],
  18.                                            [$date, $total_in, $succ_in,$pk_in,$pk_out,"$pk_hour - $pk_hour_dur hr",$total_out,$succ_out ]];
  20.     $sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
  21.                       [$max_pk_msg,$pk_msg]];
  24.     foreach(@parameters)
  25.     {
  26.     $sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
  27.     $sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
  28.     }
  30.         # print "XyzzyPerl"
  31.         $array = $sheet->Range("A2:I1")->{Value};
  32.         for (@$array) {
  33.             for (@$_) {
  34.                 print defined($_) ? "$_|" : "<undef>|";
  35.             }
  36.             print "\n";
  37.         }
  39.         # save and exit
  41.         $book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
  42.         undef $book;
  43.         undef $ex;
this code outputs everything to an excel sheet
however i need to append the data
how will i go about trying to determine the last row and insert it?
i considered using a counter but then i still need to determine the new cells of that the new data will go in
tough problem here, anyone pls advise?
Jan 25 '08 #1
6 6466
170 New Member
hm...anyone who can help? thanks alot
Jan 28 '08 #2
4,059 Recognized Expert Specialist
Sorry, I can't help. I never do anything with Excel and I have no experience with any Excel modules.
Jan 28 '08 #3
170 New Member
hm...thanks anyway
anyone else who might know by chance?
Jan 28 '08 #4
410 Recognized Expert Contributor
I didn't understand your problem quite well. But if you are just checking if data exists in a given cell and appending to next cell, a counter variable and test loop should work. For ex:
Expand|Select|Wrap|Line Numbers
  1.     $j=1;
  2.     foreach(@parameters)
  3.     {
  4.     while(defined $sheet->Cells($j,9)->{Value}) { $j++;}
  5.     $sheet->Cells($j,9)->{Value} = [$parameter_in_array{$_}];
  6.    #####
  7.    } 
Here, I'm using fixed column value, since you may want a particular data into particular column. You can use a variable too if required.
Not sure if I understood your requirement properly :(
Jan 28 '08 #5
58 New Member

Expand|Select|Wrap|Line Numbers
  1. my $last_row = $sheet -> UsedRange -> Find({What => "*", SearchDirection => xlPrevious, SearchOrder => xlByRows}) -> {Row};
Jan 28 '08 #6
170 New Member
hm...basically it's like say for my 1st row my data is:

Car A SHE3442F

then when i wanna insert data of car B, i just append it like below:

Car A SHE3442F
Car B SHA2324A

hm....i try if the last row code given by windblowsME work..
another problem i see is i need to open up my saved file to add in the infomation..wou ld it be workable still if say my first entry of data i save it in "test.xls", then at a later date if i wanna append data at "test.xls", i open the file "test.xls", does the code still works? i'm gonna try it anyway but if u got any suggestions would appreciate it!
thanks dude for the help
Jan 29 '08 #7

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

Similar topics

by: Vinay Gupta | last post by:
Hi, In a Perl to Tcl conversion project, I am planning to use the following Tcl extensions as a replacement for some Perl libraries. My development environment is Windows. Win32::OLE --> "DDE" or "OpTcl" LWP::UserAgent, HTTP::Request --> "Scotty" Net::Telnet --> "Expect" ('spawn telnet') I have used Expect but haven't used Scotty, DDE...
by: usenet | last post by:
Problem installing Win32::OLE under Cygwin. I have searched the web and found little documentation on installation procedure. Please help. I'd like to get Win32::OLE working under cygwin. Cygwin perl 5.8.6-4 Windows XP SP1
by: yma | last post by:
Hi, I tried to use a listbox to display a column in MS Access 2000 nwind.mdb by using ole DataAdapter, Connection and dataset controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I put ole DataAdapter, Connection and dataset controls and fill in the properties of the listbox. ...
by: sandycat05 | last post by:
Hello all, I am a new Perl programmer. Below is the beginnings of a code that I am using to manipulate an Excel spreadsheet via Perl using win32::OLE. However, what I'd like to do is the following: instead of either opening a file or creating a new one, I'd like to do BOTH. I was thinking of creating a loop where I could basically say something...
by: Mika M | last post by:
Hi! I'm trying to read text file like... "Field1";"Field2";"Field3";"Field4" "ABCD";"EFGH";"1234";"20051020" "AABB";"CCDD";"2468";"20051021" "CCDD";"XXYY";"4321";"20051022" ....using OLE DB-provider. Unfortunately I can't affect in what kind of
by: ajaymistry | last post by:
hi all, I'm using OLE for accessing exel spreadsheets but i don't know how to save its data to Database and how to Retrieve saved data. Im using SQL Server 2000 database. If anybody have any suggession then i'll be thankfull.
by: PRITPAL | last post by:
Hi There, I want a code for Saving and Reading formatted text (RTF File) in MS Access using ole Objects, i want to save 20 such records in DB using VB 6.0. Plz Help
by: John Randall | last post by:
Anybody got some sample code showing how to create a word doc and insert text plus images, such as .gif or jpg files? I'm new to Win32::OLE. Thanks in advance.
by: mohanprasadgutta | last post by:
Hi, I need help to open a password protected excel file in perl using Win32:OLE. when I tried to open file in normal way at the time of program execution it is prompting me to enter password. I am giving the script i used for opening excel file.. So i want to know how to provide password parameter while opening the file. use strict; use...
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...
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. ...
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...
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...
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...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.