use OLE;
$file = 'c:\path\to\file.xls';
if(!-e $file)
{
print "File does not exist";
exit 0;
}
$app = CreateObject OLE 'Excel.Application' || die "Can't open EXCEL $
+!\n";
$book = $app->Workbooks->Open($file);
$sheet = $book->Worksheets(1);
# Retrieve
$cellA1 = $sheet->Range("A1")->{'Value'};
$cellB1 = $sheet->Range("B1")->{'Value'};
print "|$cellA1|$cellB1|\n";
# Do pre-processing
$sheet->Range("A1")->{'Value'} = 'pre';
$sheet->Range("B1")->{'Value'} = 'process';
$cellA1 = $sheet->Range("A1")->{'Value'};
$cellB1 = $sheet->Range("B1")->{'Value'};
print "|$cellA1|$cellB1|\n";
$app->{'Visible'} = 1;
# USER manual input happens here
# You can let them close when done (ctrl-f4 is quick)
while($app->ActiveWorkbook) { sleep(1); }
# Or you can give them time on time
sleep(10);
# Close it up if you do time
if($app->ActiveWorkbook)
{
$app->ActiveWorkbook->Close(0);
$app->Quit();
}
# Do post-processing
$app = CreateObject OLE 'Excel.Application' || die "Can't open EXCEL $
+!\n";
$book = $app->Workbooks->Open($file);
$sheet = $book->Worksheets(1);
# Retrieve
$cellA1 = $sheet->Range("A1")->{'Value'};
$cellB1 = $sheet->Range("B1")->{'Value'};
print "|$cellA1|$cellB1|\n";
# Do post-processing work
$sheet->Range("A1")->{'Value'} = 'post';
$sheet->Range("B1")->{'Value'} = 'process';
$cellA1 = $sheet->Range("A1")->{'Value'};
$cellB1 = $sheet->Range("B1")->{'Value'};
print "|$cellA1|$cellB1|\n";
$app->save();
$app->ActiveWorkbook->Close(0);
$app->Quit();
# ThinMonk (TM)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|