Merging word template through .jsp url

I have to add a word template to an existing .jsp.  this is the code for the jsp.  when the print button is clicked, the template should be opened with the merged fields. here's the .jsp code

function printClicked () {
            document.mainForm.order_Letter_No.focus();
            document.mainForm.order_Letter_No.select();
            Copied = document.mainForm.order_Letter_No.createTextRange();
            Copied.execCommand("Copy");
            var objWord = new ActiveXObject("Word.Application");
            if (objWord != null)
              {
              var templett = document.mainForm.corres_List.options[document.mainForm.corres_List.selectedIndex].value
              
                  switch (templett)
                  {
                        case "orderletter":
                              if (document.mainForm.country_Code.value == "US") {
                                    objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/LPPCIUS.dot");      
                                    }
                                else
                                    {
                                    objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/LPPCI.dot");            
                                    }
                              break;
                        case "filingreceipt":
                              objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/filingreceipt.dot");
                              break;
                        case "noticeofpublication":
                              objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/noticeofpublication.dot");
                              break;
                        case "noticeofallowance":
                              objWord.Documents.Open("http://ncr-test/Ladas/LPPCI/noticeofallowance.dot");
                              break;                  
                        case "transmittalletter":
                              objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/transmittalletter.dot");
                              break;                        
                        case "filingpriority":
                                    objWord.Documents.Open("http://ncr-tomcat/Ladas/LPPCI/filingpriority.dot");
                                    break;
                  }            
            
            objWord.Visible = true;
//            objWord.Selection.Paste();
      }
      }
poporon5Asked:
Who is Participating?
 
GrahamSkanRetiredCommented:
OK. I hope that the main document has already been designed and the datasource set.

I'm not good with javascript, but I think it would be something like this:

                       case "mergeit":
                                    objDoc = objWord.Documents.Open("http://ncr-tomcat/merge/mergemain.doc");
                                    objDoc.MailMerge.Execute
                                    break;
0
 
GrahamSkanRetiredCommented:
What difficulty are you having? Can you not just add another case?
0
 
poporon5Author Commented:
It is not merging the data like name, address etc from the stored procedure.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
poporon5Author Commented:
Do I need to code the word template and if so can you give me an example?
0
 
poporon5Author Commented:
what should i do to make sure that the data from the .jsp for the unique matter gets on the word template?  Please help.
0
 
GrahamSkanRetiredCommented:
Not sure that I understand that.

To do a mail merge, set up the Word document in the Word with a datasource and some mergefields for the columns. There is a Wizard in Word for this if you have any difficulty. The datasource can be almost anything with a table-like structure: an excel spreadsheet, another Word document with a table; a CSV file or a database table or stored query.

If you want to change the data, load some different data into the datasource
0
 
poporon5Author Commented:
The merge data has to be from the selected record being displayed from the url or jsp page
0
 
poporon5Author Commented:
Do I need to create a  macro?
0
 
GrahamSkanRetiredCommented:
No.

Here is a sample main document and an Excel workbook as a datasource.

I have set the document as an ordinary document to prevent difficulties in not being able to find the datasource, because the path on your system will be different from mine.

In Word, ribbon 'Mailings' tab, use the 'Start Mail Merge' dropdown and select 'Letters' for the output type of the merge. Then use the 'Select Recipients' dropdown, 'Use Existing List...' item to browse to where you have save the workbook. Select Sheet1 as the table.

You can now use the 'Preview Results' button to show the data in the main document, or you can do 'Finish & Merge', The 'Edit Individual Documents' choice will produce a new output document.
Name.docx
0
 
GrahamSkanRetiredCommented:
Oops. Hit the wrong button (I think) . I'm having system problems in sending the Excel Workbook for the datasource.
0
 
GrahamSkanRetiredCommented:
Rebooted, so I'm trying again.
Clients.xlsx
0
 
poporon5Author Commented:
I'm able to merge the data using a view and produce mass mailings.  My problem is I'm having trouble linking the data referring to a specific client from the url or jsp.
0
 
GrahamSkanRetiredCommented:
Does my suggestion about adding a WHERE clause to the QueryString address that problem?
0
 
poporon5Author Commented:
it's quite possible that I'm not explaining this right.  I need to be able to pass that unique id and the other needed fields from the URL to the word document, whichever id i called through the url and only the data relating to this id,   Please help
0
 
GrahamSkanRetiredCommented:
I don't understand you request in terms of Word Mail Merge. The data needs to be from fields in the datasource. I have shown you how to modify the query programmatically in order to filter the records. Do you want to get something out of the URL, e.g, the site name, like "www.experts-exchange.com" from this URL?

 http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_27378162.html?cid=1572#a36945585

Perhaps it would help if you were to post one of your mail merge main documents (or something similar), so we can see what your situation is.
0
 
poporon5Author Commented:
how do i code so that the template will access the stored procedure and get the data of the specific customer that the user is displaying?  The data is not passing to the template to be merged.  My understanding is that the specific customer id that is being displayed has to be passed thru the User interface to the stored procedure to extract the data from the database or datasource.  Thank you.
0
 
GrahamSkanRetiredCommented:
Are you trying to use the Word Mail Merge process, with a stored procedure in a database to be the datasource?

Although I asked if the WHERE clause helped, I don't seem to have given details in this question. Perhaps you should have picked me up on that.

In a Word mail merge main document, you can see the query here:

objDoc.Mailmerge.DataSource.QueryString

It will look like this
SELECT * FROM I:\Allwork\MyAccess.mdb

You can add a filter with a WHERE clause, like this

SELECT * FROM I:\Allwork\MyAccess.mdb WHERE  LastName = 'Smith'

 
0
 
poporon5Author Commented:
how do i get that particular, for example, "smith" to be recognized automatically from the user interface.  For example, the user will pull customer smith on her screen (jsp page) by putting smith's customer id 1234.  the customer id is coming from the database.  "smith" cannot be part of the stored procedure.  customer id or "smith" is a field name in the database and the data can be '1234" or 7890.  The customer id or name "smith" gets displayed for the user when she enters the customer id or the name "smith" in the user interface.  The needed data, will then merge with the template to create the letter for only the chosen customer id.  Thank you.
0
 
GrahamSkanRetiredCommented:
Lastname was an example. It would probably be better to use the ID, which will be unique.

If you are using jsp, I expect that you know more about Web page design than I do. I have simply tried to explain about using Word Mail merge, and I'm still not sure if that is what you are trying to use.
0
 
poporon5Author Commented:
it did not completely help me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.