SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: fread an .doc

  1. #1
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fread and .doc

    can i open and read (fopen and fread) a document .doc?
    Regards from Spain.
    Last edited by marylin77; Sep 30, 2003 at 15:17.

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm....

    Hardly used COM myself though your looking for something like this ?

    PHP Code:
    ...
    $word = new COM('Word.Application');
    //
    if($word) {
    $filename 'c:/ms/word/invoicing.doc';
    $accessed $word -> Documents -> Open($filename);
    .

    Maybe look at the PHP Manual for more info ? Hope this gets you started though...

  3. #3
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Problems

    Hello,

    If all you want to do is open the Microsoft Word document, than Dr. Livingston's suggestion will work perfectly. But most people actually like to read or edit the document when they open it, and Word documents use a closed, proprietary format. Thus, you won't be able to read, edit, or manipulate the data in the document. I don't know if Microsoft is kind enough to help people out with this, but I doubt that there's another way.

    Compuwhiz7

  5. #5
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am reading here:
    http://es2.php.net/manual/en/ref.com.php
    you wrote:
    Thus, you won't be able to read, edit, or manipulate the data in the document.
    ///
    do u mean is impossible to read a document.doc via php functions??

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Sorry!

    Hello,

    As far as I know, yes, it is impossible to read a Microsoft Word document using PHP. If, however, you could somehow convert the Word document into a plain text file (.Txt), then you could read, parse, and edit such a document.

    Hope this helps...

    Compuwhiz7

  7. #7
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you could "read" it but it will mostly be gobble-de-goop (unreadable). Or in other words: open a .doc in Notepad and that's what you're going to get.
    Oh no! the coots are eating my nodes!

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know Visual Basic ?

    I don't though maybe see if you can find anything more about the COM component over at Microsoft in relation to Visual Basic/PHP ?

    --EDIT--

    convert the Word document
    Not plain text but XML perhaps ?

  9. #9
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all...All the comments had been very usefull for me Particularly,compuwhiz7's answer:
    however, you could somehow convert the Word document into a plain text file (.Txt).
    ///How i can convert it?any idea?some routine made by someone :]?
    PD: i do not know Visual Basic :[
    Regards from Spain.

  10. #10
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Course it can be done, in a round about way

    Here is a link which explains it in details, and it's really pretty simple. Just have to convert it to HTML first.

  11. #11
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at this:
    PHP Code:
    <?php
    // starting word
    $word = new COM("word.application") or die("Unable to instanciate Word");
    print 
    "Loaded Word, version {$word->Version}\n";

    //bring it to front
    $word->Visible 0;

    //open an empty document
    $word->Documents->Add();

    //do some weird stuff
    $word->Selection->TypeText("This is a test...");
    $word->Documents[1]->SaveAs("jo.doc");

    //closing word
    $word->Quit();

    //free the object
    $word->Release();
    $word null;
    ?>
    It is all right..but if i write
    $word->Documents[1]->SaveAs("jo.txt");
    the file called jo.txt is unreadable.
    Although If i open jo.doc with Microsoft Word and then i click in Save As and i write jo.txt (selecting .txt as type), then the file jo.txt is readable.
    Curious...

  12. #12
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much DJ_p@ckman...it is all right..now ( I convert the php file I want into an html file)
    Regards from Spain.
    Only one thing:
    althoug I write:
    PHP Code:
    $word->Visible 0
    I have to accept to open Microsoft Word to display the html file what I want.┐How can i do to avoid the oppening of Microsoft Word ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •