reading docx (Office Open XML) in PHP

2019-01-15 13:54发布

I want to add an word import function to our CMS, the only problem I cannot seems to find a good library for reading docx files (Word 2007).

Do anyone has some recommendations, the library should be able to extract content of the document and basic styling like italic, bold, superscript?

Thanks for your help

7条回答
我只想做你的唯一
2楼-- · 2019-01-15 14:22

I have just find a library that has both reading and writing support check it on the codeplex forge http://openxmlapi.codeplex.com and it is licensed under GPLv2 .

查看更多
来,给爷笑一个
3楼-- · 2019-01-15 14:22

Convert a docx document to a odt using OpenOffice. Use then eZ Components to do the parsing and import. They actually use the import in their CMZ eZ Publish.

查看更多
Anthone
4楼-- · 2019-01-15 14:26
祖国的老花朵
5楼-- · 2019-01-15 14:33

docx files are actually just containers for the document's XML. You should be able to unzip the docx file and then go to the word folder inside, then to the document.xml. This has the actual text. But things like the fonts and styles are in other xml files in the docx container, so you'll probably want to mess around a bit and figure out what is what and how to match it up (start by using namespaces, I bet).

But yea, unzip the file, then use simplexml to convert it into something you can actually mess around with.

查看更多
我命由我不由天
6楼-- · 2019-01-15 14:41

PHPDocX PRO includes a TransformDoc class that can read .docx (zip) files and generate XHTML (or PDF) from it:

...
require_once 'phpdocx_pro/classes/TransformDoc.inc';
$doc = new TransformDoc();
$doc->setStrFile($file->filepath);
$doc->generateXHTML();
$html = $doc->getStrXHTML();
查看更多
smile是对你的礼貌
7楼-- · 2019-01-15 14:43

Or, since you requested a library, you may want to look into something like Docvert. I was just looking around based on your question, and it's my favorite so far for PHP. You input the word file location, it transforms it into something simple with the attributes and all that good stuff.

查看更多
登录 后发表回答