在perl中不使用OLE读取/写入MS office文档(excel、word)

在perl中不使用OLE读取/写入MS office文档(excel、word),perl,Perl,如何在不使用perl中的WIN32::OLE的情况下读取MS office文档(excel,word),以便我们可以在任何需要的地方(如服务器)执行此操作。您可以使用电子表格::ParseExcel读取MS excel文件,电子表格::WriteExcel编写MS excel文件。 有关更多信息,请参阅下面的链接 要编写MS word文档(仅限RTF、.doc格式),可以尝试使用RTF::Writer 这里有更多细节 要阅读MS word文档,可以使用Text::Extract::word

如何在不使用perl中的WIN32::OLE的情况下读取MS office文档(excel,word),以便我们可以在任何需要的地方(如服务器)执行此操作。

您可以使用
电子表格::ParseExcel
读取MS excel文件,
电子表格::WriteExcel
编写MS excel文件。 有关更多信息,请参阅下面的链接

要编写MS word文档(仅限RTF、.doc格式),可以尝试使用RTF::Writer 这里有更多细节

要阅读MS word文档,可以使用Text::Extract::word

请注意,RTF::Writer或Text::Extract::Word不能用于.docx扩展名


谢谢

如果您只需要文件的文本内容,则更容易使用:

soffice --headless --convert-to txt:text file_to_convert.docx

如果你真的想提取样式和布局,你需要一个XML解析器和大量的工作。

只需要Excel文档。谢谢,伙计,我只需要阅读MS word文档并将其写入Excel文档,然后将其导入数据库。我在MS word文档中的源代码是大约1000个文件,这是一个噩梦般的工作……可能是在使用perl时没有OLE就无法打开word文件。
# object-based interface
use Text::Extract::Word;
my $file = Text::Extract::Word->new("test1.doc");
my $text = $file->get_text();
my $body = $file->get_body();
my $footnotes = $file->get_footnotes();
my $headers = $file->get_headers();
my $annotations = $file->get_annotations();
my $bookmarks = $file->get_bookmarks();

# specify :raw if you don't want the text cleaned
my $raw = $file->get_text(':raw');

# legacy interface
use Text::Extract::Word qw(get_all_text);
my $text = get_all_text("test1.doc");
soffice --headless --convert-to txt:text file_to_convert.docx