如何使用 Perl 提取 Word 文档中的数据?

发布于 2024-07-27 02:56:01 字数 32 浏览 2 评论 0原文

如何使用 Perl 从 Word 文档中提取数据?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

深海夜未眠 2024-08-03 02:56:01

如果您使用的不是 Windows,我认为最好的方法可能是首先对其进行转换。

如果您使用的不是 Windows 并且无权访问 Win32::OLE ,您可以使用 OpenOffice 来转换文档< /a>.

您可以将链接中的脚本包装到 Perl 程序中。 虽然链接以 PDF 开头,但如果您阅读它,可以将其转换为文本。 另请参阅 此 stackoverflow 帖子转换 doc 和 docx 文件

If you are not on Windows, I think the best route might be to convert it first.

If you are not using Windows and don't have access to Win32::OLE, you can use OpenOffice to convert the documents.

You could wrap up the script in the link into your Perl program. Although the link starts with PDF if you read on it can convert it to text. Also see this stackoverflow post about converting doc and docx files.

倦话 2024-08-03 02:56:01

如果脚本要在安装了 Word 的 Windows 机器上运行,则可以使用 Win32::OLE。

您使用什么平台? 也许可以调用 antiword

You could use Win32::OLE if the script is to run on a Windows box with Word installed.

What platform are you using? Perhaps antiword could be invoked?

疯了 2024-08-03 02:56:01
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";
}

此处盗取

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

一身软味 2024-08-03 02:56:01

在 Windows 上,您最好使用 COM 接口来访问 Word 功能。

如果您想跨平台执行此操作,请考虑执行“catdoc”或 libwv。

On Windows you'd better use COM interfaces to access Word functionality.

If you want to do it cross-platform think about executing "catdoc" or libwv.

楠木可依 2024-08-03 02:56:01

Word 文档不再是平面文件。 找到一个 .docx,用 .zip 扩展名重命名它,然后您可以打开它并在里面翻阅以了解内容的布局方式。 我总体上同意微软已经提供了做到这一点的方法。

Word docs are no longer flat files. Find a .docx, rename it with a .zip extention, and you can open it up and poke around inside to get a feel for how things are laid out. I would generally agree though that microsoft has provided ways to do this already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文