SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Filling Word Doc from Mysql Database Using Php

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Filling Word Doc from Mysql Database Using Php

    Good day Mr. Moderator.
    I have a challenge presently. I have a project I'm working and I'm provided with a template by my client ( a word document template with spaces like name, address etc to be filled in from the database or web form. I have worked on getting the info stored in the database but the challenge is how do I get the info from the database to fill in the placeholders in the word document so that they can download it and print it out. Any advice or suggestion will be highly appreciated. Thanks a lot.

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,736
    Mentioned
    46 Post(s)
    Tagged
    3 Thread(s)
    Maybe use a PDF instead?
    You could then create the PDF dynamically using a library such as Zend_Pdf and populate it with the relevant information from your database.
    Here's a tutorial on PHP master to get you started: http://phpmaster.com/generating-invoices-with-zend_pdf/
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,954
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    I agree with @Pullo ;

    I was part of a maintenance team that had to support a web application that filled out Word documents about a year ago. The problem we ran into was pretty big, first Word is the only Office product by Microsoft that does not support multi-threading. Secondly, getting the instance to close properly and consistently was a nightmare, so we ultimately ended up with multiple instances that would all take up large amounts of memory, because Word was never designed in a Server scenario. Lastly, the changes that occurred between versions to the WordML and the likes made it a maintenance nightmare as you tried to support multiple versions.

    If you can talk the client into using a PDF, there are some nice PDF frameworks out there. fpdf is the one I consistently use.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    1,866
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    The problem we ran into was pretty big, first Word is the only Office product by Microsoft that does not support multi-threading.
    More than just Word I'm afraid. IMO, whatever MS Office is built on is garbage. When running more than one product in the Office line, if one of them hang, they all hang, even Microsofts built in clock / calendar on the task bar.

    Quote Originally Posted by cpradio View Post
    Secondly, getting the instance to close properly and consistently was a nightmare, so we ultimately ended up with multiple instances that would all take up large amounts of memory, because Word was never designed in a Server scenario.
    Probably wrote in VBA?

    Stay far far away from MS Word if possible. PDFs are the way to go.
    <?php
    //Kyle Wolfe
    echo devBlog("My Dev Notes");

  5. #5
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,954
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    Probably wrote in VBA?

    Stay far far away from MS Word if possible. PDFs are the way to go.
    No, it was written in .NET using the API's provided by Microsoft for handing Office applications. Nonetheless, I would never recommend interacting with a Microsoft Product via a web application (or desktop for that matter) ever again (not that I have recommended it).

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    1,866
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Nonetheless, I would never recommend interacting with a Microsoft Product via a web application (or desktop for that matter) ever again (not that I have recommended it).
    @cpradio ; Ditto
    <?php
    //Kyle Wolfe
    echo devBlog("My Dev Notes");

  7. #7
    From space with love SitePoint Award Recipient SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,301
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    http://dev.mysql.com/doc/refman/5.0/...wordexcel.html

    I don't know if that would work for the online version of office
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  8. #8
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Why not just create a styled web page to display the information? They can print that directly and you wouldn't need to use any proprietary software, or download any files.
    Keith
    Freelance web developer
    http://www.duvalltech.com/

  9. #9
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot everyone who have taken their time to respond to my question. I think pdf is the way to go and I've studied fpdf within the last 2 days to see how easy it'll be to implement. Though the tables making up the document is quite complex but I should be able to get it done. My other worry is how to fill in the spaces in the document with result from the database. I hope fpdf supports that. Thanks a lot

  10. #10
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,954
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by papadammy View Post
    Thanks a lot everyone who have taken their time to respond to my question. I think pdf is the way to go and I've studied fpdf within the last 2 days to see how easy it'll be to implement. Though the tables making up the document is quite complex but I should be able to get it done. My other worry is how to fill in the spaces in the document with result from the database. I hope fpdf supports that. Thanks a lot
    This is what I usually do with fpdf
    1. Download fpdi
    2. Take the existing word document or template and turn it into a PDF (especially if it only contains the static content)
    3. Using fpdf with fpdi, load the template and then write whatever text you need on top of the template to produce the final PDF


    Sample code:
    PHP Code:
      require_once('pdf-templates/fpdf.php');
      require_once(
    'pdf-templates/fpdi.php');

      
    $pdf = new FPDI('P''pt''Letter');
      
    $pdf->AddPage('P''Letter');
      
    $pdf->setSourceFile('template.pdf');
      
    $templatePage $pdf->importPage(1);
      
    $pdf->useTemplate($templatePage0000true);

      
    $pdf->Image($itemData->qrcodeAbsolutePath49064000"png");

      
    $pdf->SetFont('Arial''B'28);
      
    $pdf->SetTextColor(1593132);
      
    $pdf->SetXY(28180);
      
    $pdf->MultiCell(028$boatDescription0'C'false); 
    Hopefully this should get you started. I've had great success with this route.

  11. #11
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much Cpradio for your response. I will surely try it. Please can you put me through on the procedure of displaying the results from my mysql database in the resulting pdf and how to mail it to the concerned client right away. I know how to extract from the database but the challenge is to how input it into fpf and create the final pdf document. I understand how cell work in fpdf but I've not seen any example on how to use result from the database in fpdf. Thanks in advance

  12. #12
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,954
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by papadammy View Post
    Thanks so much Cpradio for your response. I will surely try it. Please can you put me through on the procedure of displaying the results from my mysql database in the resulting pdf and how to mail it to the concerned client right away. I know how to extract from the database but the challenge is to how input it into fpf and create the final pdf document. I understand how cell work in fpdf but I've not seen any example on how to use result from the database in fpdf. Thanks in advance
    Sure, if you look at my prior code example, just replace $boatDescription, and the other variables with the $row['column'] of your MySQL result and you'll be good to go.

    As for how to e-mail it, that part requires a bit of work.
    1. First you will need to call the Output method using the "Save" parameter http://www.fpdf.org/en/doc/output.htm
    2. Then you will need to either a) create a mail framework that works with attachments, or b) find one that allows you to easily add attachments. I suggest PHPMailer

  13. #13
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much Cpradio. Your input has been of immense help. I'll work on it.

  14. #14
    SitePoint Zealot
    Join Date
    Jul 2012
    Location
    Scarborough, North Yorkshire, United Kingdom
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see you seem to have settled on generating a PDF (correct choice) but if anyone is interested I did lots of work with WordML many moons ago so know its possible - http://www.codeproject.com/Articles/...-WordML-Basics
    Richard
    Resell SSL Certificates - API / WHMCS / HostBill / ClientExec
    ServerTastic - RapidSSL, Geotrust, Thawte, Symantec, SmarterTools and more

  15. #15
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Richard, I'll chek out your work as well. I just want to get through with this load in front of me first.

  16. #16
    SitePoint Zealot
    Join Date
    Jul 2012
    Location
    Scarborough, North Yorkshire, United Kingdom
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops, sorry I wasn't too clear.

    I didn't create the linked to content, just found it useful before
    Richard
    Resell SSL Certificates - API / WHMCS / HostBill / ClientExec
    ServerTastic - RapidSSL, Geotrust, Thawte, Symantec, SmarterTools and more

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
  •