Trying the following:
-----------------------------------------
use Win32::OLE;
use Win32::OLE::Enum;
$filename = "$ARGV[1]";
$document = Win32::OLE -> GetObject($filename);
open (FH,">$ARGV[0]");
print "Extracting Text ...\n";
$paragraphs = $document->Paragraphs();
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{
$style = $paragraph->{Style}->{NameLocal};
print FH "+$style\n";
$text = $paragraph->{Range}->{Text};
$text =~ s/[\n\r]//g;
$text =~ s/\x0b/\n/g;
print FH "=$text\n";
}
-----------------------------------------
...whcih I got off a website. Works fine when I run it through the perl
command line entering argv's. However, when I incorporate it in a CGI
script:
-----------------------------------------
#!E:/perl/bin/perl.exe
#use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
use Win32::OLE;
use Win32::OLE::Enum;
use constant UPLOAD_DIR => "M:/temp/cgi-uploads/";
use constant BUFFER_SIZE => 16_384;
use constant MAX_FILE_SIZE => 1_048_576; # Limit each upload to 1 MB
use constant MAX_DIR_SIZE => 100 * 1_048_576; # Limit total uploads to 100
MB
use constant MAX_OPEN_TRIES => 100;
$CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = MAX_FILE_SIZE;
my %filespec = ( Word => ".doc",
PowerPoint => ".ppt",
Excel => ".xls",
Access => ".mdb"
);
my $q = new CGI;
print "Test";
$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );
my $file = $q->param( "filetoupload" ) || error( $q, "No file
received." );
my $fh = $q->upload( $file );
my $buffer = "";
my $outputf = "textoutput.txt";
print length($fh);
if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) {
error( $q, "Upload directory is full." );
}
# Allow letters, digits, periods, underscores, dashes
# Convert anything else to an underscore
my $file = $q->param( "file" );
$file =~ s/([^\w.-])/_/g;
$file =~ s/^[-.]+//;
# Open output file, making sure the name is unique
until ( sysopen OUTPUT, UPLOAD_DIR . $filename, O_CREAT | O_EXCL ) {
$filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e;
$1 >= MAX_OPEN_TRIES and error( $q, "Unable to save your file." );
}
# This is necessary for non-Unix systems; does nothing on Unix
binmode $fh;
binmode OUTPUT;
# Write contents to output file
while ( read( $fh, $buffer, BUFFER_SIZE ) ) {
print OUTPUT $buffer;
}
close OUTPUT;
sub dir_size {
my $dir = shift;
my $dir_size = 0;
# Loop through files and sum the sizes; doesn't descend down subdirs
opendir DIR, $dir or die "Unable to open $dir: $!";
while ( readdir DIR ) {
$dir_size += -s "$dir/$_";
}
return $dir_size;
}
sub error {
my( $q, $reason ) = @_;
print $q->header( "text/html" ),
$q->start_html( "Error" ),
$q->h1( "Error" ),
$q->p( "Your upload was not procesed because the following error
",
"occured: " ),
$q->p( $q->i( $reason ) ),
$q->end_html;
exit;
}
print
$page->header({-content-type=>'text/html',-pragma=>'no-cache',-cache-control
=>'no-store'});
$document = Win32::OLE -> GetObject(UPLOAD_DIR . $filename);
open (FH,">$outputfile");
print "Extracting Text... please wait (this may take a while)...\n";
$paragraphs = $document->Paragraphs();
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{
$style = $paragraph->{Style}->{NameLocal};
print FH "+$style\n";
print "+$style\n";
$text = $paragraph->{Range}->{Text};
$text =~ s/[\n\r]//g;
$text =~ s/\x0b/\n/g;
print FH "=$text\n";
print "=$text\n";
}
-----------------------------------------
...I get the following error:
"Can't call method "Paragraphs" on an undefined value at convert.pl..."
Now, from what I can figure out, Win32::OLE isn't loading the file which was
uploaded temporarily. The file is there in the upload directory, Win32::OLE
just can't grab it as an object. Any ideas, anyone?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs