win32::ole and excel question

Reply

Join Date: Apr 2005
Posts: 3
Reputation: droolin is an unknown quantity at this point 
Solved Threads: 0
droolin droolin is offline Offline
Newbie Poster

win32::ole and excel question

 
0
  #1
Aug 7th, 2006
History of what is trying to be accomplished:

Currently where I work, we receive a large number of excel documents which are used to manually change pl/sql scripts for updating oracle database's. From my research, I have found that oracle can not read excel documents, least not till 9.0, and then I think only as a csv file type.
In an effort to remove as much manual intervention(I cant beleive they manually change this pl/sql script every time), I am trying to come up with a method to have the excel document saved into a csv format. Then I will either use sql loader, or change the existing scripts to use this file for processing.

In that I kinda, maybe, just a bit know perl. I have done my research in this area to find a solution. I have found that the win32::ole can be used to both read and write excel documents. As I understand things, the ole is an api to the excel engine and should be able to perform all the functions that you normally can manually. All of the examples that I have found have shown individual cells being read or written. I beleive this method would just be loaded with overhead, and would not be the correct path to follow. What I would like to do is have perl via win32::ole open the excel document, and do a save as to an .csv format. I feel that this would be alot less overhead and would be tons faster.

I am not a object programmer, so I always have to bang my head off the wall before I get op modules to work with perl. I was going to start looking for vb scripts that perform this function, and have them converted to perl.

Any sugestions on how I might go about this????

Any help would be greatly appriceated. Thank you in advance.

Dan
Last edited by droolin; Aug 7th, 2006 at 12:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: win32::ole and excel question

 
0
  #2
Aug 8th, 2006
does excel have a native command for "save as csv"?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 3
Reputation: droolin is an unknown quantity at this point 
Solved Threads: 0
droolin droolin is offline Offline
Newbie Poster

Re: win32::ole and excel question

 
0
  #3
Aug 8th, 2006
I was looking at cpan with regards to the documentation there for the win32::ole. They have an example of a perl script there for excel, and the last line that you see in this is:

  1. # save and exit
  2. $book->SaveAs( 'test.xls' );

Now, with regard to your question. There are three options to save a file as .csv in excel: Comma Delimited, MS-DOS, and Macintosh.

If I just specify the following:
  1. # save and exit
  2. $book->SaveAs( 'test.csv');

I am unsure what format it would save in with regard to csv. Shoot, I'm wondering if this will save in pure excel format but just with a different file extension.

Sooooo, the answer to your question is yes. But, multiple ways.

Dan
Last edited by droolin; Aug 8th, 2006 at 1:34 pm. Reason: Remove smileys, spell check
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 1
Reputation: _raz_ is an unknown quantity at this point 
Solved Threads: 0
_raz_ _raz_ is offline Offline
Newbie Poster

Re: win32::ole and excel question

 
0
  #4
Aug 16th, 2006
Hi Dan,

Win32::OLE is not working for me. I'm using cygwin perl. ActiveState's perl might be better.

Both solutions below worked for me

A) have a look here:
http://www.cpan.org/authors/id/A/AN/...xls2csv-1.7.pl

B) this one works too:

#!/usr/bin/perl

use strict;
use Spreadsheet:arseExcel:imple;

my $filename = shift or die "Usage: xls2csv.pl file.xls\n";

$filename =~ /(.*)\.xls$/i or die "Invalid filename: $filename";
my $prefix = $1;

my $xls = Spreadsheet:arseExcel:imple->read($filename);

foreach my $sheet ($xls->sheets)
{
my $worksheet = $sheet->sheet;
my $sheetname = $worksheet->{Name};

open(CSV, ">$prefix-$sheetname.csv") or die "output file: $!";
while ($sheet->has_data)
{
my @row = $sheet->next_row;
print CSV join(';', @row), "\n";
}
close(CSV);
}

__END__

for both solutions, you need to get & install the modules
Spreadsheet:arseExcel
Spreadsheet:arseExcel:imple
from cpan.org
these might have dependencies on other modules that need to be resolved

cheers
Ralph
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC