How can I extract data in a Word document using Perl?

前端 未结 5 476
鱼传尺愫
鱼传尺愫 2021-01-21 22:23

How to extract the data from a word doc using Perl?

5条回答
  •  花落未央
    2021-01-21 23:08

    use Win32::OLE;
    use Win32::OLE::Enum;
    
    $document = Win32::OLE -> GetObject($ARGV[1]);
    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";
    }
    

    stolen from here

提交回复
热议问题