$Book->SaveAs({Filename => "F:\\Assess\\Assessment.csv",
FileFormat => 6, #xlCSV,
CreateBackup => 0});
...cleaned up any (text) fields with commas in them -- my biggest problem. Can you tell me where I might find the various options for "FileFormat" documented? The documentation installed with the module on my Windows Active State Perl installation isn't very comprehensive. The best piece of guidance I've found on this module was online at http://www.tek-tips.com/faqs.cfm?fid=6715.
After finding your second response (almost a month after you posted it), I revisited this project and extended it a little to correct for situations where users enter a 1 or 2 digit code where my accounting program will expect to find a three digit code with leading zeros. By formatting the range containing the codes before saving the file as CSV I can correct for that.
My current version (still a work in progress), here...
use strict;
use warnings;
use Win32::OLE;
my $fildir = "./";
opendir DIR, $fildir;
my @files = grep { /.xls/ } readdir(DIR);
closedir DIR;
foreach my $files (@files) {
chomp $files;
my $Excel=Win32::OLE->new('Excel.Application');
$Excel->{Visible}=0;
$Excel->{DisplayAlerts}=0;
my $Book = $Excel->Workbooks->Open("C:\\Monks\\$files") or die "Ca
+n't open file";
my $sheet = $Book -> Worksheets(1);
$sheet -> Range ('A:A') -> {NumberFormat} = "000";
my $nmlng = length $files;
my $nwnam = substr ($files,0,($nmlng - 4));
$Book->SaveAs({Filename => "C:\\Monks\\$nwnam.csv",
FileFormat => 6, #xlCSV,
CreateBackup => 0});
unlink ($files);
$Excel->Quit;
}
...checks the current directory for any excel files and pulls them into an array. Then each entry in that array is pushed through the routine you provided and the export file is like named with the CSV extant.
Typical excel data would look like: Code,PropertyName,Unit Count,Unit Cost, Total Cost, TypeAbbreviation,
+Comments
1,First Account,5,10.00,50.00,cod,User text here
002,"Second Account, The",10,20.00,200.00,cod,More narrative
003,Third Account,5,20.00,100.00,cod,Another comment
I've had no success finding a way to make the filepaths in the... my $Book = $Excel->Workbooks->Open("C:\\Monks\\$files") or die "Can't
+open file";
$Book->SaveAs({Filename => "C:\\Monks\\$nwnam.csv",
...sections dynamic. I tried "$files", "./$files" and "$fildir/$nwnam.csv" without success. Any ideas? It would be great if I could use the same code no matter where the user chooses to put the files as long at the compiled perl program is in the same directory with the excel workbooks.
In my many google searches, many people suggest creating VB Macros in Excel then converting them to comparable statements in Win32::Ole. However I've not had any luck finding any beginner's tutorials or samples of how to do that. If you can suggest a source or process, I'd appreciate it.
Thanks again. As a interested (but novice) Perl programmer, people like you and most of the other Monks who take the time to point the way are what keeps me from quitting in frustration.
|