Perl OLE Open Existing Workbook & Worksheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prasanna CRN
    New Member
    • Mar 2011
    • 11

    Perl OLE Open Existing Workbook & Worksheet

    Hi Friends,
    I am trying to open particular Worksheet from MS Excel workbook (WIN32 :: OLE).

    I cannot able to work on particular sheet. Please help me on this :

    Code:
    $Excel = Win32::OLE->GetActiveObject('Excel.Application');
    $Excel->{'Visible'} = 0;	
    $Excel->{DisplayAlerts}=0;	
    					
    # Open File and WorkSheet	
    $Book = $Excel->Workbooks->Open("d:\test.xls");	 	
    $Sheet = $Book->WorkSheets(1)->{marks};	 
    $Sheet = $Book->WorkSheets($Sheet);
    $Sheet->Activate;
    
    $LastRow = $Sheet->UsedRange->Find({What=>"*",   SearchDirection=>xlPrevious,    SearchOrder=>xlByRows})->{Row};
    $LastCol = $Sheet->UsedRange->Find({What=>"*",   SearchDirection=>xlPrevious,    SearchOrder=>xlByColumns})->{Column};
    	
    $mylastcol = 'A';	
    	
    for ($m=1;	$m < $LastCol;	$m++){
    		$mylastcol++;			
    }
    		
    print "Last Row in Sheet $ARGV[2] : $LastRow, Last Col : $LastCol\n";
    [B]$_	=	$Sheet -> Range("A7") -> {Value};
    print "Value of Test Cell : $_ \n";[/B]
    	
    $Book->Close();
    $Excel->Quit();
    Please point me what went wrong. Its giving Error at $sheet->Activate itself!!

    One More thing : If i want to print content of the cells, i am storing it in $_ and printing it. Is there is other way to print content of cells within 'Print' Statement?
    Last edited by miller; Apr 13 '11, 06:28 PM. Reason: code tags
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    I never play around with Win32::OLE but instead use Spreadsheet::Pa rseExcel and Spreadsheet::Wr iteExcel.

    Here's a tutorial on Win32::OLE that might help though: http://search.cpan.org/~gsar/libwin3...ICROSOFT_EXCEL

    Comment

    Working...