Link to home
Start Free TrialLog in
Avatar of sekhar2000
sekhar2000

asked on

Dynamic word document creation

Hi Friends,
    Please find the following requirement as follows.
we are planning to build a web based interface to build a resume(Only in organisation specific format) in word document using asp.Please help me the best way for developing the same.

    NOw we are planning to go for word templates.
1)Creating organisation specific word template.
2)Provide the web interface to the user to enter his details.
3)Read the through an asp page and save it in the word template.


   Please let me know how to access the word template and update the data.

   Thanks for all your suggessions and anyswers to my queries.

Thanks&REgards
chandu
chandrak@infotech.stph.net


Avatar of sybe
sybe

Usually Word is not installed on a web-server, and if it is not installed, your can not use the "Word.Application" object.

An alternative is then to create RTF documents. RTF is just like HTML a plain text format. You'll have to study it a bit to find out how to create what you want. But maybe you can also create some "templates" by saving your desired format from Word as RTF.
Then:
- Open a template using FileSystemObject
- Do some Replace functions on it when inserting content.
- Send the RTF document with the right contenttype to the browser, or save it on the server, whatever you wish.



Avatar of sekhar2000

ASKER

Thanks SYBE for your valuable answer.
Could you please send me the sample code which will explain more about the requirement?
I never worked on rtf files so far.
  Please provide me the sample code how to access the sample RTF file and saving it on to the server.

REgards
chandu
I once made a number of functions to create RTF documents from ASP. It is a while ago, so I am not really into it now. But here's the introduction to my functions, plus some sample functions (i did not check whether the urls mentioned are still working)

========================================
'    - create RTF documents from ASP
'        some basics about RTF (Rich Text Format)
'        * all code must be between { }, the document starts with it, and ends with it.
'        * The escape sign in RTF is \, so \} will produce a }, and \\ a single \.
'        * It has some things common with HTML, like "tags".
'            RTF-tags are for example /b (bold), /b0 (end bold), /par (paragraph)
'        * An important difference are the font- and color-tables,
'            at the beginning of the document the font- and the color-table define which colors
'            and fonts can be used throughout the document. They get a code which is to be referred to
'            when writing text. For example "f1" can be defined as the code for "Arial".
'            The RTF-tag /f1 will then display the Arial font. With colors it works about the same.
'        * Tables work much in the same way, in the sense that they have a table definition.
'            And then it is just a matter of adding rows....
'
'     - RTF-documents can be saved as files using filefunctions.inc, just give them extension .doc or .rtf
'    - If you wish to let the users open the result directly in word: use
'            Response.ContentType = "application/msword"
'        That will even change the extension of the document to .doc if users chose to download it.
'    - urls:
'        http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q270906
'        http://www.biblioscape.com/rtf15_spec.htm
'        http://www.dubois.ws/software/RTF/
'        http://msdn.microsoft.com/library/?url=/library/en-us/dnrtfspec/html/rtfspec.asp?frame=true


Function RTFStart()
    RTFStart = "{\rtf1 \ansi" & CHR(10) & CHR(13)
    RTFStart = RTFStart & RTFColorTable()
End Function

Function RTFEnd()
    RTFEnd = "}"
End Function

'-------------------------------------------------------------------------------
' RTFColorTable()
' Purpose:        Write the colortable of an RTF document
' Assumes:
' Inputs:        -
' Returns:        string
' Remark:        The last programmed string is longer and maybe better...
'-------------------------------------------------------------------------------

Function RTFColorTable()
    RTFColorTable = "{\colortbl;\red0\green0\blue0;\red0\green0\blue255;"
    RTFColorTable = RTFColorTable & "\red0\green255\blue255;\red0\green255\blue0;"
    RTFColorTable = RTFColorTable & "\red255\green0\blue255;\red255\green0\blue0;"
    RTFColorTable = RTFColorTable & "\red255\green255\blue0;\red255\green255\blue255;}" & CHR(10) & CHR(13)


    ' extended
    RTFColorTable = "{\colortbl;\red0\green0\blue0;"
    RTFColorTable = RTFColorTable & "\red0\green0\blue255;\red0\green255\blue255;"
    RTFColorTable = RTFColorTable & "\red0\green255\blue0;\red255\green0\blue255;"
    RTFColorTable = RTFColorTable & "\red255\green0\blue0;\red255\green255\blue0;"
    RTFColorTable = RTFColorTable & "\red255\green255\blue255;\red0\green0\blue128;" & CHR(10) & CHR(13)
    RTFColorTable = RTFColorTable & "\red0\green128\blue128;\red0\green128\blue0;"
    RTFColorTable = RTFColorTable & "\red128\green0\blue128;\red128\green0\blue0;"
    RTFColorTable = RTFColorTable & "\red128\green128\blue0;\red128\green128\blue128;"
    RTFColorTable = RTFColorTable & "\red192\green192\blue192;}"& CHR(10) & CHR(13)
End Function


'-------------------------------------------------------------------------------
' RTFFontTable()
' Purpose:        Write the fonttable of an RTF document
' Assumes:
' Inputs:        iOption (int)
' Returns:        string
' Remark:        This creates the "fonts" table. The fonttable creates references to
'                    all fonts used in the document. I don't know a lot about fonts though..
'-------------------------------------------------------------------------------

Function RTFFontTable(iOption)

    RTFFontTable = "{\fonttbl"

    Select Case CheckIntegerZero(iOption)
        Case 0
            ' minimal option: f0 = "Times New Roman", f1 = "Arial", f2 = "Courier New"
            RTFFontTable = RTFFontTable & "{\f0\froman\fprq2\fcharset0 Times New Roman;}"
            RTFFontTable = RTFFontTable & "{\f1\fswiss\fprq2\fcharset0 Arial;}"
            RTFFontTable = RTFFontTable & "{\f2\fmodern\fprq1\fcharset0 Courier New;}"

        Case 1
            ' standard option: f3 = "SF Sans Serif", f4 = "Verdana"
            RTFFontTable = RTFFontTable & "{\f0\froman\fprq2\fcharset0 Times New Roman;}"
            RTFFontTable = RTFFontTable & "{\f1\fswiss\fprq2\fcharset0 Arial;}"
            RTFFontTable = RTFFontTable & "{\f2\fmodern\fprq1\fcharset0 Courier New;}"
            RTFFontTable = RTFFontTable & "{\f3\fswiss\fprq2\fcharset0 SF Sans Serif;}"
            RTFFontTable = RTFFontTable & "{\f4\fswiss\fprq2\fcharset0 Verdana;}"

    End Select

    RTFFontTable = RTFFontTable & "}" & CHR(10) & CHR(13)

End Function

Just to get an idea:
Create a word document, type some text into it, and then save it as Rich Text Format (File/Save As).

Then open the document in a plain text editor, you'll see that RTF is plain text, and that Word puts a lot of garbage around the text you typed in the Word document.

I remember that I did a search on component that do a HTML to RTF conversion. I found some, but they were not meeting my expectations. Maybe you are lucky to find such a component.
If you go the easy way then do the follwing:

* create the word documents with the templates you want to use. At the plave where you want to insert the name, type something like "@name@", and do the same for all variables in the doument (the basic idea is same as is being used for mail-merge).
* save the different templates as RTF and put them on the server.
* create the HTML-webbased form, with elements for user-input -> the fields should relate to the @name@ etc in the templates.
* process the form in an ASP page. The ASP page should:
- open the desired template using FileSystemObject, and put it in a string.
- Replace in the template text @name@ with the actual name as was filled in on the form, and repeat that for all form-elements.
- Save the resulting string as a RTF file, or send it to the browser (whatever you want).

The code for this does not require anything very advanced.
If you would like to use COM components, then you can easily make your own COM component that calls MS word and creates a new document and then inserts text into it and so on. You can then stream this document back to to the user. Sybe is right that they usually don't install word on a web server but for a website like this, i think that you would ideally get a dedicated server. You can then install word onto it as that is your initial requirement and you can also then run your custom COM objects that you would make. If you need any other help with this then let me know.
sekhar2000,

First, I have to ask you if you are locked into creating Word templates using ASP?  

This is a very difficult approach since Word is NOT designed to run on a server with any user interaction.

If you would like to share how you are going to use the Word templates, perhaps we can suggest alternate approaches that would be considerably easier to implement.

You may want to review the following Microsoft KB article:
Considerations for Server-Side Automation of Office
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757

An exert from this article:
=================================================
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when run in this environment.
==================================================

Even if you use RTF, it's a very complicated approach.

Here is just one alternate approach:  Use ASP to save the data in a DB.  Then the user can use the mail-merge feature with Word to create the resume.

Some questions:

1.     When you say a Word template, do you actually mean a Word .dot file?  Or do you just mean Word document?

2.     Do you want the ASP to create a new Word doc from a Word template using the data from the ASP form, and then send this Word doc to the user?

3.     Is this for a Intranet or Internet app?

4.     Are all users on the same LAN?
Using the server to create .doc files is a bad idea unless you have a serious server farm that can balance server load... since the process to create a .doc file is very intensive on the processor...

Microsoft posted a MSDN article a while back that outlined the details, and the problems...
Hi All,
     Thanks for your valuable suggessions.Still I am find the best approach to fulfill our requirement.

    Please find the about the application as follows..

(We are not stick to one approach.Finding different design approaches which will fits the requirement).


1)Our basic intension is creating the resume of each one in a generic format of the company.
   so that we are providing the interface for filling perticular user info in HTMLformat.
2)Read the info from the ASP page and save it as word document or PDF based on requirement.Right now we are implementing it as word document.




Answers to apollois as follows..

1.     When you say a Word template, do you actually mean a Word .dot file?  Or do you just mean Word document?

Ans:
    A .dot file.


2.     Do you want the ASP to create a new Word doc from a Word template using the data from the ASP form, and then send this Word doc to the user?

Ans:
Yes.exactly.

3.     Is this for a Intranet or Internet app?
Intranet application
4.     Are all users on the same LAN?
Ans:
  same Lan


  Please don't hesitate to ask any sort of quetions to know exactly about our requirement.
 

Thanks &Regards
chandu
Hi All,
     Thanks for your valuable suggessions.Still I am find the best approach to fulfill our requirement.

    Please find the about the application as follows..

(We are not stick to one approach.Finding different design approaches which will fits the requirement).


1)Our basic intension is creating the resume of each one in a generic format of the company.
   so that we are providing the interface for filling perticular user info in HTMLformat.
2)Read the info from the ASP page and save it as word document or PDF based on requirement.Right now we are implementing it as word document.




Answers to apollois as follows..

1.     When you say a Word template, do you actually mean a Word .dot file?  Or do you just mean Word document?

Ans:
    A .dot file.


2.     Do you want the ASP to create a new Word doc from a Word template using the data from the ASP form, and then send this Word doc to the user?

Ans:
Yes.exactly.

3.     Is this for a Intranet or Internet app?
Intranet application
4.     Are all users on the same LAN?
Ans:
  same Lan


  Please don't hesitate to ask any sort of quetions to know exactly about our requirement.
 

Thanks &Regards
chandu
Hi Friends,
      goGBgo  Please let me know the approach how can we implement the functionlity using components?

      Still I am looking for the best approach to create a resume in word document dynamically.

    Please let me know if we have any third party components which will match our requirement.
   
 
 REgards
chandu
sekhar2000,

If your primary requirement is to create resumes in Word format for users on you LAN, why don't you develop the entire system using Word templates, Word forms, and Word automation, and do not use the Web?

You can easily create a Word form that the user will fill in, and then using Word automation, save the data to your DB and create the final word document.  You will have much more control over the Word document this way.

Does this make sense to you?

Best Regards,
apollois
Dear apollois ,
      Could you please elborate it with an example.so that I will get more picture on it.what components we need to use for the same.
Regards
chandu
sekhar2000,

The only component you have to have is Microsoft Word (I'd recommend Word 2000 or later).  Optionally, you can use a DB like MS Access, MSDE, or MS SQL Server.  It just depends on you needs.

One approach would be something like this:

1.     Design a Word form using Word.  Save this as a Word template (.dot).  Use this form to collect the data you want to use in the resume.  Depending on how you want the user to enter the data, you could just make the form also be the resume format.

2.     If you want to save the data in a DB, at the bottom of the form a button that runs a Word VBA procedure (stored in the template).  This VBA proc will save the data to your DB, and then opens a new Word document based on another Word template that is the resume template.

3.     The Word resume template will contain the resume format with bookmark fields where you want to output the data from either the Word form or from the DB.

Here is a good MS white paper that will get you started on using Word to generate reports (like a "resume" report from a DB):
http://www.microsoft.com/worddev/articles/movs108.htm


Here are some other references you find useful:

Microsoft Office 2000/Visual Basic Programmer's Guide
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeopg/html/deovroffice2000visualbasicprogrammersguide.asp


Office XP for Developers
http://www.microsoft.com/office/developer/default.asp

MSDN Office Site
http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28000550

Does this answer your question?
Dear apollois,
   Thanks you very much for your valuable answer.
Please give me some time so that I will find more about your answer.
Thanks&Regards
chandu
Dear apollois,
   Thanks you very much for your valuable answer.
Please give me some time so that I will find more about your answer.
Thanks&Regards
chandu
Hi sekhar2000,

I hope your evaluation and testing has gone well.

There have been a number of good answers proposed.  Please take action in a timely manner to close this question.  

Please select the comment as an answer that was most helpful to you.  In case of duplicate or very similar comments you can select the one posted first.

For guidelines on grading, see Tip #11 at:
http://cd-eepages.fateback.com/asking.html


Best Regards,
apollois
ASKER CERTIFIED SOLUTION
Avatar of apollois
apollois

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi guys.
I used the anwers and comments below (especially the sybe'one) this way:

1)created my .rtf file in Word
2)opened it as text (notepad) and copied everything

3)in asp page:
...
Response.ContentType = "application/msword"

'Create the string sRTF with the copied text

sRTF = "{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang3082"& _
       "{\f2\fmo....." & request.write("myvariable")

'Finally:

Response.Write sRTF


Everything is ok, but the pages loads quite slowly.
Can I speed it up?

Some notes:
my rtf file is very small(6k)
I tried dividing sRTF in small chunks with partial response.write(s), but unluckily
I used response.buffer & flush with no success.

Any hint?

TIA

Regards

KIRIL
KIRIL,

Thanks for selecting my comment as answer, but I'm not sure if that's what you intended to do.  You made a comment about  using sybe's comment.

If you used only sybe's comment as the solution, then you should award the answer and points to him.

If you used more than one expet's comments in coming up with a solution, then you can split the points among them.

If you wish to change your selected answer, or split the points, then post a zero-point question with Community Service (https://www.experts-exchange.com/Community_Support/) stating your request, and include a link to this question.


As to why your page loads so slow, I'm not sure.  Please post all the code for your page.

Best Regards,
apollois
I must admit that I find myself slowly losing interest in answering questions.

For more then one reason, but one of the reasons is that it happens far too often that the accepted answer is not the comment that made the first/largest contribution to the answer. This is one example. I am not very point-hungry, but an accepted comment (from me) gives me some satisfaction, especially in cases in which i really tried.
Greetings All,

I've been reading the suggestions to the original problem and trying to see if it answers my problem.

I'm currently developing an ASP web application and I want to submit the data from the web form to a SQL DB and as a Word Document (.doc) attachment to my boss.

The only thing that I'm new to is placing the web form results into a Word document.

For those that have had success with this. Would you mind displaying your code. I'm not getting the full picture with the tidbits.

I could create a new question so I can award points!!!

Thanks In Advance,

tamrsand
I agree with sybe... you have accepted an answer to this Q, if you need more help post a new Q.