So I am trying to find a cell in a spreadsheet. I entered "findme" in the cell and I want to return the cell next to it. So if "findme" was in A1, I want to return B1. If I hard code the script to find "findme" it works just fine. I want to prompt the user so it can be more versatile, but it will not work correctly. Any Ideas?
#use warnings;
#use strict;
use Cwd;
use OLE;
use Win32::OLE::Const "Microsoft Excel";
#-----------------------"Copy From" Destination-----------------------
+--
my ( $xl_report ) = ( "c:/perl/energy.xls" );
my ( $excel, $workbook, $sheet, $row, @data,$i, $j,$char,$char2,$pri
+ntme,$FindMe, @FindMe );
$excel = CreateObject OLE 'Excel.Application';
$excel -> {Visible} = 1;
$excel -> {EnableEvents} = "false";
#-----------------------Formating and Setup----------------------
+-----
$workbook = $excel -> Workbooks -> Open ( "$xl_report" ) or &te
+rminate ( "open $xl_report" );
$sheet = $workbook -> Worksheets( "info" );
$sheet -> Activate;
#---------------------Search for Text-----------------------------
+---
#print "Find what !?\n";
#$FindMe = <STDIN>;#I also tried multiple types
for ($j=1; $j<27; $j++)#loop to go through Columns
{
$FindMe= findme;
$char= chr($j+64);
$char2= chr($j+65);
for ($i=1; $i<30; $i++)#loop to go through Rows
{
if (($sheet -> Range ( $char . $i ) -> {Value}) eq $FindMe)
{
$data = $sheet -> Range ( $char2 . "$i" ) -> {Value};
}
}
}
$sheet -> Range ( "Z" . 1 ) -> {Value} = $data;
print "ENDDATA: $data";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.