updating word file using php

Discussion in 'PHP' started by c4cyber, Jul 7, 2009.

  1. #1
    hi guys!
    here is my problem...

    I have to append a string "See the solution file" in at the end of almost 3000 MS word (.doc) files.

    I am using this

    $file="filename.doc";
    $fp=fopen($file, "a+");
    $cmnt="See the solution file";
    fwrite($fp, $cmnt);
    fclose($fp);

    it works fine if i use

    $file="filename.txt"; or $fp=fopen($file,"w+");
    txt file(need to update doc) (writing whereas i need to append data)

    what to do?
    need solution on urgent basis...
    thanks in advance
     
    c4cyber, Jul 7, 2009 IP
  2. zain654321

    zain654321 Peon

    Messages:
    202
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    $word = new COM("word.application") or die ("couldnt create an instance of word");
    echo "loaded , word version{$word->version}";
    //bring word to the front
    $word->visible = 1;
    //open a word document
    $word->Documents->Add();
    //add some text to the document
    $word->Selection->TypeText("this is some sample text in the document");
    //save the document as sampleword.doc
    $word->Documents[1]->SaveAs("sampleword.doc");
    //close word
    $word->Quit();
    //free object resources
    $word->Release();
    $word = null;
    ?>
    --------------------------------------------------------
     
    zain654321, Jul 7, 2009 IP
  3. anthonywebs

    anthonywebs Banned

    Messages:
    657
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    not on a linux server
     
    anthonywebs, Jul 8, 2009 IP
  4. c4cyber

    c4cyber Well-Known Member

    Messages:
    1,039
    Likes Received:
    27
    Best Answers:
    1
    Trophy Points:
    150
    #4
    its not working...i need to append data in already existing files... whereas this code is writing text to a new word file, removes previous data and ask to save...it would be hazard to save 3000 files.
     
    c4cyber, Jul 8, 2009 IP