SPUG: Newbie problem with Win32::OLE
Tracie Edelson
traciee at wrq.com
Wed Nov 29 19:07:10 CST 2000
I'm pretty comfortable doing basic stuff with Perl but this is my first
foray into both Win32 object programming and using modules. However, I am
pretty good at winging it :) I adapted the module part of this code straight
from the ActiveState documentation for the module.
In a nutshell, I am importing some text files from Unix, "converting" them
to .csv files. I then open the .csv files in Excel and "save as" Excel files
(.xls). The whole thing works great, except that when I open the "converted"
.xls files, the data is no longer columnar (it is a single line separated by
commas.
I give up!
Help?
#Openview Performance Graphs -- create .csv
$rawdata="d:\\OpenView\\rawdata\\";
$csvfolder="d:\\OpenView\\csvfolder\\";
$xlsfolder="d:\\OpenView\\monthlytest\\";
chomp $rawdata;
chomp $csvfolder;
############################################################################
######
opendir RAWDATA, $rawdata or die "Cannot open the directory $rawdata\n";
while ($dirlist= readdir RAWDATA) {
chomp $dirlist;
if ($dirlist =~ /^\.+/) {
}else {
foreach ($dirlist) {
#print "$dirlist\n";
$file = "$rawdata$dirlist";
open FILE, $file;
while ($line = <FILE>){
#print "$line\n"
$line =~
s/(^\S+)\s(\S+)\s(\S+)\s(\S)/$1,$2,$3,$4/;
$csvfile = "$csvfolder$dirlist.csv";
open NEWFILE, ">>$csvfile";
print NEWFILE "$line";
}
close NEWFILE;
close FILE;
}
}
}
opendir CSVFOLDER, $csvfolder or die "Cannot open the directory
$csvfolder\n";
while ($dir = readdir CSVFOLDER) {
chomp $dir;
if ($dir =~ /^\.+/) {
}else {
foreach ($dir){
use Win32::OLE qw (in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLEWarn=3; #die on errors
$ex =
Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit'); # use the Excel application
if it's open, otherwise open new
$ex->{Visable} =1;
$workbook = $ex->Workbooks->Open("$csvfolder$dir");
$workbook->SaveAs
("$xlsfolder$dir.xls")->{FileFormat}=
xlExcel9795->{ReadOnlyRecommended}=False;
$ex->ActiveWorkbook->Close(0);
}
$ex->Quit();
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list