Monday, February 22, 2010

Word Document Generation in ASP.net or PHP

This question comes from Wendy.

Mike,

I have a programmer question. I am not a programmer but looking to hire one to do a project for me. I am not sure how much info you need to know to answer my question but basically - I want a program that asks questions to people they answer the questions then these questions are used to make a word document. I have asked for a programmer to write the program in ASP.net. I have someone that wants to do it in PHP? Does it really matter?

Wendy

I'll answer your question at the end of the response, but I feel that it's my duty as a programmer and open source advocate to give you a quick lecture on the general topic at hand :)

I find that most decisions that I've made to require a specific format have come back to bite me. I suppose the first question to ask yourself is why Word? Would RTF work fine? What about PDF?

I'm sure you have your reasons, but please be sure to consider all your options and also all the consequences. The less-proprietary your output formats are, the more portable your application will be in the long run. I've never personally worked with the MS Word format before, but I can assure you that the number of tools available as well as the number of qualified programmers who are able to use these tools to make this happen are few in number.

Compare that to the number of tools and qualified programmers who are able to work with more open formats. If you try your search again, I promise you will be pleasantly surprised. Furthermore, because of the number of good tools and programmers available, you can usually get this work done at a much lower cost (assuming your programmer bills you hourly, that is).

Ok. So that you are fully aware of the best way to begin your search for a solution to this problem, you can stop reading this response and go hire a programmer can offer some suggestions to you on the best method of implementation, considering this as well as the other business requirements that you have.

Anyway, I think you can solve this without ASP.NET. From what I understand the DOCX file format can be a document template of sorts which maps data placeholders to nodes in an XML document. Here's what I think you'll need to get this done at least to prototype quality (meaning right now):

  • A DOCX template
  • Few valid XML documents
  • A programmer who's familiar with VB and XPATH

Put them all in a box, shake for 10 minutes and you should have what you're looking for.

Please refer to these two articles which I found for you. The app they build is more complex than what you're looking for... but should illustrate the concepts well.

http://blogs.msdn.com/erikaehrli/archive/2006/08/11/word2007DataDocumentGenerationPart1.aspx

http://blogs.msdn.com/erikaehrli/archive/2006/08/11/word2007DataDocumentGenerationPart2.aspx

Good luck

Readers: It's your turn.

Am I right? Wrong? Agree? Disagree?

3 comments:

  1. Ignoring the open vs proprietary for the moment, there are options for MSword and open source. Perl has a module that is interesting, and more germane to this discussion is the explanation offered by the module's author. It turns out you can create raw HTML documents with a few additions and rename them to .doc and VOILA! You have a word document! The Perl module can be found at http://search.cpan.org/~dami/MsOffice-Word-HTML-Writer-0.04/lib/MsOffice/Word/HTML/Writer.pm

    Based on that a PHP programmer should be able to emulate/recreate what is required without much effort (if he/she understands Perl).

    ReplyDelete
  2. I think the only important aspect of which language you can/should use is where you want to be able to run the program. If its PHP, you need to have a web server to host it on. If you have a place in mind you want to put it, PHP would be a fine choice. You originally were thinking ASP.net, which I believe would also require this, so it looks like PHP would suit you fine. (I find this to be the main reason for choosing a particular language for a simple standalone business app like this.)

    As for the document format, try to keep in mind that its very easy to open either a text file or a word file in MS WORD and convert it to the other format (just use "Save as...").

    But consider both cases. In one case, you start with a text file directly from your program and you can read that virtually anywhere.

    In the other case, you start with a .docx and you better have access to MS WORD or you can't read your file without some big headaches. Unreadable output means your program is now useless to you. Just a thought, us software types are always scanning the road ahead for headaches like this.

    Honestly, it shouldn't be very difficult to have the programmer make the program allow users to choose the output file format (which could default to a .docx, for instance) as long as you don't get carried away and try to support every file type under the sun.

    Just thought I'd chime in. (I agree with the original answer, but thought these points could use some expansion.)

    ReplyDelete
  3. Hi, I have a question on a flash mp3 player for website. I have the script from a freeware giving away programers, but they do charge for modification of customasation.
    How the program works? It gets the files info from a folder, writes them in XML and plays them in alphabeticaly order.
    My question is, how to sort mp3 files by their name in descending order? Or, best, having a schuffle facility for the program?
    regards

    Script site: http://www.flashmp3player.org/

    ReplyDelete