Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

I want to open word document and save as plain text with Encoding option MS-DOS and Insert-Line-Break option.

I achieved the requirement, but output not matching with the output which is done using the same by manual operation in MS-word. ie., line breaks not coming properly

My code: 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=>wdFormatDOSTextLineBreaks}); $Word->{ActiveDocument}->Close; $doc->Close; $Word->Close;

Replies are listed 'Best First'.
Re: Save As option in Win32::OLE
by wfsp (Abbot) on Jun 17, 2009 at 09:09 UTC
    Try this
    #! /usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const q{Microsoft Word}; # wd constants my $Word = Win32::OLE->new(q{Word.Application}); $Word->{'Visible'} = 0; $Word->{DisplayAlerts} = 0; my $doc = $Word->Documents->Open(q{c:/somepath/chapter1.doc}); $doc->SaveAs( { FileName => q{c:/somepath/chapter1.txt}, FileFormat => wdFormatDOSTextLineBreaks } ); $doc->Close; $Word->Close;
Re: Save As option in Win32::OLE
by Anonymous Monk on Jun 17, 2009 at 07:37 UTC
    What is wdFormatDOSTextLineBreaks?

      Please open word docuemnt and type one para with 5 lines of text. Save as ".txt" plain text file it will ask some options. click in Flie conversion option". if you choose these options then it will convert the text as per word format. Now your five line docuemnt converts to five lines of text. each line seperated by enter marks. otherwise as per docuemnt it will come as single line complete para.
      Hope you understand now.

        How does your answer relate to what the definition or value of wdFormatDOSTextLineBreaks is? You use it in your code but you don't show where it comes from.

Re: Save As option in Win32::OLE
by Anonymous Monk on Jun 17, 2009 at 07:38 UTC