How do I apply formatting to a particular word in a docx file using Win32::Ole in Perl?

北战南征 提交于 2019-12-04 16:47:51

Try using the Words method instead of Text.

Untested:

while ( defined (my $paragraph = $enumerate->Next()) ) {

    my $words = Win32::OLE::Enum->new( $paragraph->{Range}->{Words} );

    while ( defined ( my $word = $words->Next() ) ) {

        my $font = $word->{Font};
        $font->{Bold} = 1 if $word->{Text} =~ /Perl/;
    }
}

I dont know anything about perl. But you look at office open xml

You can use treat the .docx file as a zip file, and do a simple search and replace, wich works a million times quicker than the interop. and you dont have to worry about the million things that can go wrong with it also.

Rename your .docx file to .zip and open it and you will see what I mean.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!