Avatar of poporon5
poporon5

asked on 

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();
      }
      }
Microsoft WordJSP

Avatar of undefined
Last Comment
poporon5
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

What difficulty are you having? Can you not just add another case?
Avatar of poporon5
poporon5

ASKER

It is not merging the data like name, address etc from the stored procedure.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of poporon5
poporon5

ASKER

Do I need to code the word template and if so can you give me an example?
Avatar of poporon5
poporon5

ASKER

what should i do to make sure that the data from the .jsp for the unique matter gets on the word template?  Please help.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of poporon5
poporon5

ASKER

The merge data has to be from the selected record being displayed from the url or jsp page
Avatar of poporon5
poporon5

ASKER

Do I need to create a  macro?
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Oops. Hit the wrong button (I think) . I'm having system problems in sending the Excel Workbook for the datasource.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Rebooted, so I'm trying again.
Clients.xlsx
Avatar of poporon5
poporon5

ASKER

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.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Does my suggestion about adding a WHERE clause to the QueryString address that problem?
Avatar of poporon5
poporon5

ASKER

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
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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 "https://www.experts-exchange.com" from this URL?

 https://www.experts-exchange.com/questions/27378162/Merging-word-template-through-jsp-url.html?cid=1572&anchorAnswerId=36945585#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.
Avatar of poporon5
poporon5

ASKER

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.
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of poporon5
poporon5

ASKER

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.
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of poporon5
poporon5

ASKER

it did not completely help me.
Microsoft Word
Microsoft Word

Microsoft Word is a commercial document editing program that is part of the Microsoft Office suite. It features numerous text-editing tools for creating richly formatted documents, along with tools for the use of macros in Word documents. Word's native file formats are denoted either by a .doc or .docx file extension. Plugins permitting the Windows versions of Word to read and write formats it does not natively support, such as the OpenDocument format (ODF) are available. Word can import and display images in common bitmap formats such as JPG and GIF. It can also be used to create and display simple line-art.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo