Generate Ms word Document in linux

Discussion in 'PHP' started by ade_ari_w0, Jan 15, 2008.

  1. #1
    Please tell me code for generate Ms word document include image in linux.

    Thank you.
     
    ade_ari_w0, Jan 15, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    Are you asking for a php code that generate a MSWORD document with image in it,can you explain a lil bit more

    Regards

    Alex
     
    kmap, Jan 15, 2008 IP
  3. ade_ari_w0

    ade_ari_w0 Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes. but i don't know the code to generate it in linux.
    please help me.
    /thank you.
     
    ade_ari_w0, Jan 15, 2008 IP
  4. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As far as I know, it's very difficult if not impossible for PHP.

    M$ binary format is very complex, so even openoffice and abiword can not read it 100% correct.

    If you use java, you may take a look at Apache POI (http://poi.apache.org/).
    If you use c, you may take a look at wvware(wvware.sourceforge.net/).
     
    hostingcoupon, Jan 15, 2008 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I've done it successfully with PHP, but it required hundreds of lines of code so I'm not going to attempt to go into great detail here.

    The easiest way is to duplicate Word's "single file HTML" document format, which is basically a MIME package containing the document in Word's spastic HTML plus all the images and related resources.

    If you create a document in Word and save it in that format, you can open it in a text editor and see how it looks. From then it's just a straightforward matter of reverse-engineering.
     
    SmallPotatoes, Jan 15, 2008 IP
  6. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Do you use PHP to call backend commands?
    like, exec('convert file.foc file.html');
     
    hostingcoupon, Jan 15, 2008 IP
  7. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Me? No, the Word file is constructed piece-by-piece, all in PHP code.
     
    SmallPotatoes, Jan 15, 2008 IP
  8. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Do you mean the "single file HTML" document format, or the true .doc format?
    Mind share your php code? ;)
     
    hostingcoupon, Jan 16, 2008 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It's the single-file HTML format, but from the perspective of a Word user, it's indistinguishable. You can name the file xxxx.doc and Word will open it. It supports all the features of a Word document, including embedded images, change tracking, and so on.

    Unfortunately I cannot share the code as I was paid some $30K to develop the software of which it's a component, and I don't own it. But as I mentioned above, you can easily reverse engineer the format by looking at a few saved files. There's also some documentation online at the Microsoft site, but frankly, I found that tinkering with files, saving them in Word, and looking at the results in a text editor was a lot more helpful.
     
    SmallPotatoes, Jan 16, 2008 IP
  10. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #10
    Sounds simple, I might try it out, did you use regular expression or simple str_replace?
     
    Kaizoku, Jan 16, 2008 IP
  11. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #11
    In a nutshell, it's a bunch of template substitution, plus some extra work to assemble the MIME components.
     
    SmallPotatoes, Jan 17, 2008 IP