Re: Save As option in Win32::OLE

Bill Luebkert <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Ramkumar wrote:
> Jan wrote:
>> You need to show the complete code.  I would suspect that you are not
>> including the Word constants using Win32::OLE::Const.  If you are
>> using "strict" and "warnings" then you would have been told by Perl.
> 
>> But without seeing your complete source it is impossible to tell.
> 
>> You also didn't mention how the script output is different from
>> the manual output.
> 
> Complete code:
> 
> 	use Win32::OLE;
> 	use Win32::OLE::Const 'Microsoft Word';
> 
> 	my $folderpath=$ARGV[0];
> 
> 	my $Word = Win32::OLE->new('Word.Application');
> 	$Word->{'Visible'} = 0;
> 	$Word->{DisplayAlerts} = 0;
> 	my $doc = $Word->Documents->Open("$folderpath\\Chapter 1.doc");
> 	$Word->ActiveDocument->SaveAs({FileName=>"$folderpath\\Chapter
> 1.txt", FileFormat=>wdFormatTextLineBreaks});
> 	$Word->{ActiveDocument}->Close;
> 	$doc->Close;
> 	$Word->Close;

I only have Word 2000 to test with, but this seems to work (not actually
sure what the Dos LB Text is vs reg DOS - assume it just wraps long lines):

use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

# only have Word 2000 to test with ...

my $folderpath = $ARGV[0] || 'E:/NeedFullPathHere/TestuseWin32.doc';

print "new\n";
my $Word = Win32::OLE->new('Word.Application') or die "new: $! ($^E)";

$Word->{'Visible'} = 0;
$Word->{DisplayAlerts} = 0;

print "open $folderpath\n";
my $Doc = $Word->Documents->Open($folderpath) or die "Open: $! ($^E)";

$folderpath .= '.txt';	# make save as name

print "saveas $folderpath\n";
my $ret = $Word->ActiveDocument->SaveAs({FileName => $folderpath,
   FileFormat => wdFormatTextLineBreaks}); # or die "SaveAs: $! ($^E)";
# getting an undef return here, but file is still saved
printf "ret=%s\n", defined $ret ? $ret : 'undef';

print "ADClose\n";
$Word->{ActiveDocument}->Close;

print "DocClose\n";
$Doc->Close;

print "WordQuit\n";
$Word->Quit;		# changed to quit

__END__
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.