?
Solved

Merging word template through .jsp url

Posted on 2011-10-03
20
Medium Priority
?
349 Views
Last Modified: 2012-06-27
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();
      }
      }
0
Comment
Question by:poporon5
  • 10
  • 10
20 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36906877
What difficulty are you having? Can you not just add another case?
0
 

Author Comment

by:poporon5
ID: 36907018
It is not merging the data like name, address etc from the stored procedure.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1500 total points
ID: 36907086
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:poporon5
ID: 36909537
Do I need to code the word template and if so can you give me an example?
0
 

Author Comment

by:poporon5
ID: 36910654
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36910924
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
 

Author Comment

by:poporon5
ID: 36911249
The merge data has to be from the selected record being displayed from the url or jsp page
0
 

Author Comment

by:poporon5
ID: 36911565
Do I need to create a  macro?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36912239
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36912286
Oops. Hit the wrong button (I think) . I'm having system problems in sending the Excel Workbook for the datasource.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36912360
Rebooted, so I'm trying again.
Clients.xlsx
0
 

Author Comment

by:poporon5
ID: 36912663
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36913500
Does my suggestion about adding a WHERE clause to the QueryString address that problem?
0
 

Author Comment

by:poporon5
ID: 36945585
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36947900
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
 

Author Comment

by:poporon5
ID: 36948333
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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1500 total points
ID: 36948602
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
 

Author Comment

by:poporon5
ID: 36950174
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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1500 total points
ID: 36950282
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
 

Author Closing Comment

by:poporon5
ID: 37059565
it did not completely help me.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question