473,323 Members | 1,551 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,323 software developers and data experts.

How to append excel sheet using win32::OLE

170 100+
hi all,

i've got the following program that needs yr help:
Expand|Select|Wrap|Line Numbers
  1. use Win32::OLE;
  2.  
  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.         }
  10.  
  11.  
  12.         # get a new workbook
  13.         $book = $ex->Workbooks->Add;
  14.     $sheet = $book->Worksheets(1);
  15.  
  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 ]];
  19.  
  20.     $sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
  21.                       [$max_pk_msg,$pk_msg]];
  22.  
  23.  
  24.     foreach(@parameters)
  25.     {
  26.     $sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
  27.     $sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
  28.     }
  29.  
  30.         # print "XyzzyPerl"
  31.         $array = $sheet->Range("A2:I1")->{Value};
  32.         for (@$array) {
  33.             for (@$_) {
  34.                 print defined($_) ? "$_|" : "<undef>|";
  35.             }
  36.             print "\n";
  37.         }
  38.  
  39.         # save and exit
  40.  
  41.         $book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
  42.         undef $book;
  43.         undef $ex;
  44.  
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?
thanks
Jan 25 '08 #1
6 6446
poolboi
170 100+
hm...anyone who can help? thanks alot
Jan 28 '08 #2
KevinADC
4,059 Expert 2GB
Sorry, I can't help. I never do anything with Excel and I have no experience with any Excel modules.
Jan 28 '08 #3
poolboi
170 100+
hm...thanks anyway
anyone else who might know by chance?
:)
Jan 28 '08 #4
nithinpes
410 Expert 256MB
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.    } 
  8.  
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
Try

Expand|Select|Wrap|Line Numbers
  1. my $last_row = $sheet -> UsedRange -> Find({What => "*", SearchDirection => xlPrevious, SearchOrder => xlByRows}) -> {Row};
Jan 28 '08 #6
poolboi
170 100+
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..would 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

2
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"...
2
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. ...
1
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...
3
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:...
5
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...
0
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...
0
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
5
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.
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.