Jump to content

How to Edit a MS Word Document


dpicella

Recommended Posts

I want to add some text to the end of some Microsoft Word documents.  Is there a way to do this?

 

I'm on a Linux server and therefore can't use COM to open an instance of a Word application.

 

Basically, this would be like inserting some text such as a time stamp at the end of the .doc file.

 

If php can't do this, what about Perl?  Thanks!

Link to comment
Share on other sites

I don't know exactly how to edit a Microsoft Word document through PHP, but I can outline how it might be done.

 

<?php
    $str = 'The text to append to the Microsoft Word Document';
    $file_handle = fopen('/path/to/MS_Word_document.doc', a);
    fwrite($file_handle, $str);
    fclose($file_handle);
?>

 

I'm not sure that would work, but it should be a push in the right direction.

Link to comment
Share on other sites

Thanks!

 

Well... that did not work.  I did notice that the text does get added at the end of the file stream but it does not show up in word.  The word file seems to be encoded in binary format and not ascii.

 

Perhaps there is a Perl script that can edit a word file???

Link to comment
Share on other sites

Thanks!

 

Well... that did not work.  I did notice that the text does get added at the end of the file stream but it does not show up in word.  The word file seems to be encoded in binary format and not ascii.

 

Perhaps there is a Perl script that can edit a word file???

In that case...

Try

$file_handle = fopen('/path/to/MS_Word_document.doc', 'ab');

instead of

$file_handle = fopen('/path/to/MS_Word_document.doc', 'a');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.