RE: Save As option in Win32::OLE

"Ramkumar" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Organization PMG
Message-ID <[email protected]>
Hi Bill,

Thanks for your reply and suggestions. I tested using your same code in word
2003. No changes with my previous output. But I need OUTPUT WITH LINE BREAKS
for each line for a single paragraph.

Ex:
{{Without Line Breaks - Single paragraph - Current Output}}
    Writing, of whatever type, can be a draining and dreaded task.   But it
can also be a passion, an adventure, and even a compulsion that occasionally
brings great satisfaction as a payoff to the pain.   One group of people
write simply because it is demanded of them by employers (or teachers).  A
second group set down words because they like to write.  And a special third
group may internally be compelled to pen things due to changes in the brain
that Alice Flaherty and colleague neurologists label hypergraphia, "an
overpowering desire to write." [1]  
 
{{With Line Breaks - Single paragraph - Required output}}
    Writing, of whatever type, can be a draining and dreaded task.   But it
can also be a passion, 
an adventure, and even a compulsion that occasionally brings great
satisfaction as a payoff to 
the pain.   One group of people write simply because it is demanded of them
by employers (or 
teachers).  A second group set down words because they like to write.  And a
special third 
group may internally be compelled to pen things due to changes in the brain
that Alice Flaherty 
and colleague neurologists label hypergraphia, ?an overpowering desire to
write.? [1]  

Regards,
Ramkumar,


-----Original Message-----
From: Bill Luebkert [mailto:[email protected]] 
Sent: Wednesday, June 17, 2009 2:34 PM
To: [email protected]
Cc: [email protected]
Subject: Re: Save As option in Win32::OLE

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.