Search code examples
phpopenxmldocx

edit uploaded docx file in PHP


I need to open uploaded .docx file and possibility to change values. I know, that docx file consists of xml files. So, the main question is maybe somebody know a good WYSIWYG web-based xml editor? I know one called XOPUS, but i have no idea how to configure it. Maybe somebody knows other alternatives for that task or advices, how to put xml file to textfield, where i could change values.


Solution

  • There are a couple of PHP toolkits that you can use for this task, first off there's an early dev on on codeplex:

    http://openxmlapi.codeplex.com/
    

    However you may b better off with one of the more mature ones:

    http://holloway.co.nz/docvert/index.html
    http://www.phpdocx.com/
    

    Both of these can convert from docx to most of the popular formats, HTML included.

    Once you've converted to something like HTML, then you can use an onscreen editor such as tiny MCE:

    http://www.tinymce.com/
    

    To provide in page rich editing capabilities, before finally using the above toolkits to convert back to DOCX or any other applicable format.

    Update February 2014

    Since I first wrote this reply things have moved on. The open xml kits I mentioned above are still valid, however in page editing is now more of a possibility than ever using the new HTML5 content editable and edit mode attributes.

    It's now insanely easy to add your own buttons (Using something like bootstrap) above a div that has a content editable attribute attached to it.

    Connecting the buttons to "document.execCommand" can then send, bold, italic, underline, link & image creation, list insertion and all manner of other HTML constructions methods directly to this div without needing anything like tinyMce or another in page editor anymore.

    There is full details available on the Mozilla developer network, and I am planning o do a blog post on using this stuff very soon.