Re: Scripting data extraction from excel files in a directory.
by Corion (Patriarch) on Jul 09, 2007 at 19:15 UTC
|
| [reply] [d/l] |
Re: Scripting data extraction from excel files in a directory.
by sgt (Deacon) on Jul 09, 2007 at 21:34 UTC
|
Are the files big? If not, say each file <50M, I would read all the excel files using Spreadsheet::ParseExcel and create some dbm-like database (perl hash on disk) with some extra fields to later ease up your task of summarizing the data.
For this simple "database" the modules AnyDBM_File, MLDBM or DBM::Deep come to mind or even simple serializing to a file using YAML o
Data::Dumper-like modules.
Maybe you can use a common origin in days to facilitate the drawing of a chart or table
so that a pre-calculated record could be: issue, date0, date1, date1 - date0 (in days), day0, day1 (day0 and day1 taken with respect to an arbitrary origin -- easy to do with Date::Manip or Date::Calc). For the drawing I would use one of the Chart::* modules or gnuplot.
cheers
--stephan
| [reply] |
Re: Scripting data extraction from excel files in a directory.
by DACONTI (Scribe) on Jul 09, 2007 at 19:31 UTC
|
Hi ark989!
Please do not start to convert your data back and forth!
Excel read and even writing is an easy task with Perl!
I'm used to do all sort of things with Excel.
To start up try to play with Win32::OLE for example. (http://search.cpan.org/~jdb/libwin32-0.27/OLE/lib/Win32/OLE.pm)
Best regards,
Davide
| [reply] |
Re: Scripting data extraction from excel files in a directory.
by jbullock35 (Hermit) on Jul 10, 2007 at 11:56 UTC
|
| [reply] |
Re: Scripting data extraction from excel files in a directory.
by Tabari (Monk) on Jul 10, 2007 at 08:49 UTC
|
Hello
The following code snippet might help you in basic manipulation of the excel sheet
use strict;
use Win32::OLE;
# write a value in the first empty ro of the first column
# an excel workbook containing a sheet called Versions
my $projsheet = 'c:\temp\t.xls';
my $val = 123;
my $ex = new Win32::OLE 'Excel.Application' or die;
eval ("\$ex->Workbooks->Open(\'$projsheet\')") or die;
#
# find empty row
#
my $rowcounter = 1;
my $rowval = 1;
while (($rowval) && ($rowcounter < 1000)) {
$rowval = eval "\$ex->Workbooks(1)->Worksheets(\'Versions\'
+)->Cells($rowcounter,1)->{Value}" ;
$rowcounter++;
}
$rowcounter--;
#
# fill in the values in the sheet
#
eval "\$ex->Workbooks(1)->Worksheets(\'Versions\')->Cells($rowcoun
+ter,1)->{Value}= \'$val\'" ;
#
# save and quit
#
$ex->Save;
$ex->Quit;
return 1;
You will further need to do some ad hoc scripting to avoid message boxes generated by Excel. A good starting point is to record the macro in Excel, look at it in VB and then mimic it in perl.
Tabari
| [reply] [d/l] |
|
|
Why are you using the eval statements, and why are you using the string form of the eval statements when calling Excel methods? In my experience, the direct way works just as well and looks far less ugly:
...
$rowval = $ex->Workbooks(1)->Worksheets('Versions')->Cells($rowcounter
+,1)->{Value}
...
| [reply] [d/l] [select] |
|
|
I used the eval method to be sure that $rowcounter was evaluated before the operation on the object was executed.
As to the string form of the eval , it is the only one known to me, are there any others?
Tabari
| [reply] |
|
|
Re: Scripting data extraction from excel files in a directory.
by fernandes (Monk) on Jul 09, 2007 at 22:59 UTC
|
I have written an indexed module called Text::Statistics::Latin that performs some works related to your needs.
You can start by choosing a way to open your files, one each time, and writing output that will be opened again etc. Would be indispensable to use regex, in my opinion. So, start thinking in a procedure to open-write-read sequencies and handling data with regex.
I also sugest to convert your Excel (c) files into CSV files. If so, my module could realy be usefull as inspiration.
| [reply] |