in reply to Re: help needed urgent
in thread Copy to Excel spreadsheet

$row = 0; #================================= #Opens Excel to work on use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); $Win32::OLE::Warn = 3; # Die on Errors. Win32::OLE->new('Excel.Application')->{DisplayAlerts} = "False"; # OPENING INPUT FILE #============================ my $Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) +|| die "Oops, cannot start Excel"); #OPen Excel file my $excelfile = 'c:\\test\\inputsheet.xls'; #File that is opened + to be edited my $Book = $Excel->Workbooks->Open($excelfile); + my $Sheet = $Book->Worksheets("Example"); #Open sheet in docume +nt $Sheet->Activate(); #========================================== #GET INPUT DATA FROM INPUTSHEET.XLS #============================ $Sheet->Range("b$col ")->Select(); #========================================== $rowi = 1; flag = 0; $refcode = " "; while($sheetip->Range("b$row")->has_data) #==== { my $inputcode = $sheetip->range("b$rowi"); maxrow = $sheetop->range(); $rowop =1 for($rowop = 1; $rowop<maxrow;$rowop++) $sheetop->range("b$row"); if (strcompare($inputcode,$currentcode) { $currentrowop = $rowop $rowop = $maxrow + 1; } else $rowop++; } if(flag = 0) { $refcode = $currentcode } else flag = 1; $sheetop->range(==== if($currentcode = $retcode) $ sheetop->range ("$currentrowop")->{value}=$defect else $sheetop->range ("$currentrowop)->{value}=$defect; $rowi++; } # OPENING OUTPUT FILE #============================ my $Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) +|| die "Oops, cannot start Excel"); #OPen Excel file my $excelfile1 = 'c:\\test\\testmetrics.xls'; #File that is open +ed to be edited my $Book1 = $Excel->Workbooks->Open($excelfile1); + my $Sheetop = $Book->Worksheets("TQ-CETK"); #Open sheet in docu +ment $Sheetop->Activate(); #========================================== $Book->Save(); #Saves updated file $Excel->ActiveWorkbook->Close(0);#Closes file $Excel->Quit(); #Stops excel from running undef $Excel; #Cleanup Win32::OLE->new("Excel.Application")->{DisplayAlerts} = "True";# Turn +them back on (just in case) # ................................ Close the input & output chann +els .......... # close (LOGFILE) ; # close (OUTFILE) ;

20050119 Janitored by Corion: Added code tags, as per Writeup Formatting Tips.

Replies are listed 'Best First'.
Re^3: help needed urgent
by talexb (Chancellor) on Jan 19, 2005 at 18:04 UTC

    OK, good, now we have something to work with. What part of this script is not behaving the way you expect it to?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Basically i have to read data from a excel spread sheet and write data in other excel sheet. 2. Now while doinng this ih ave to first sort and match a particular name in the excel sheet and then put that names address in other column in the excel sheet

        To repeat my original question,

          What part of this script is not behaving the way you expect it to?

        You should know ;) that I'm step-Dad to a thirteen and a seventen year old, both boys. I can be like a dog with a bone, and ask the same question of them a dozen times or more until I get an answer to the question. The seventeen year old has figured it out, but the thirteen year old hasn't got it yet -- I keep asking the question until I get an answer. Yeah, I'm an Aries.

        This approach may make me unpopular here, but I'm going to repeat the qustion. What part of the script is not behaving the way you expect it to?

        Don't tell me again what you have to do with some Excel spreadsheet. That's been asked and answered. Tell me something new, something about what it's not doing. Let's make some progress here. Like my .sig says used to say Life Is Short. Let's get something done here. Answer the qustion.

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

        Update: Sorry, lost track of what my .sig said. It used to say "Life is short! Get Busy!" or something like that.