Hello,
I'm trying to import some data into excel. I'm using Win32::ODBC to grab
the data, and then using FetchRow to assign each row of data into a hash.
Excel complains if there's an uninitialized value in any of the cells, so
I'll have to test for that when I'm looping through the data.
My code is below. I've been able to successfully test for an empty fields
with the $ttl field - however, I'm concerned that adding that logic to every
field will slow things down. Since I'm new to programming - I feel like
there's a cleaner way to handle this. I'd also prefer to have the variable
names dynamically generated from the keys in the hash - instead of the way
I've done it below. I'm using strict, so I keep running into problems with
my variables not having an explicit package name. I'd appreciate any
suggestions, and thanks for your patience with my newbie code.
/mark
<snip>
$db = new Win32::ODBC($dsn);
if (!$db){
die "Error connecting: " . Win32::ODBC::Error() . "\n";
}
if ($db->Sql($sql)) {
print "Error submitting SQL statement: " . $db->Error() . "\n" . $sql;
}
else {
my $Row = 2;
while($db->FetchRow()){
my %Data = $db->DataHash();
my $fname = $Data{fname};
my $lname = $Data{lname};
my $ttl = $Data{ttl};
if ($ttl) {
$ttl = $ttl;
} else {
$ttl = "";
}
my $ttlcode = $Data{ttlcode};
my $company = $Data{company};
my $address = $Data{address};
my $city = $Data{city};
my $state = $Data{state};
my $zip = $Data{zip};
my $zip4 = $Data{zip4};
my $faxnum = $Data{faxnum};
my $phone = $Data{phone};
$Worksheet->Range("A$Row:L$Row")->{Value} = [
"$fname","$lname","$ttl","$ttlcode","$company","$address",
"$city","$state","$zip","$zip4","$faxnum","$phone"
];
++$Row;
}
}
$db->Close();
$Workbook->SaveAs("$datasrc_path\\datasrc.xls");
$Excel->Quit();
</snip>
----------------------------------
Mark D. Veerman
Veerman & Associates
[EMAIL PROTECTED]
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs