1
0
-1

Dear All,

I create project in Java using Word POI. I create word file using Java POI. so I need to same in Joget that

when user creates new employee then this user get mail (which I create in Joget) and Need to Mail get attached word file containing his Appointment Letter using Java POI Code

Please help me 

Here is my Java code which creates Word File below which I want to implement in Joget

 

package apachepoidoc;
import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Date;

import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.Borders;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;

public class Consultant {

public static void main(String[] args) throws Exception {
try{
String username = "G200716";
Date today = new Date();
String todaysdate = today.toString();
String usergender = "Male";
String userinitial = "";
String userfullname = "XYZ";
String userpancard = "ABCDE1235F";
String userdesignation = "Accountant";
String userstate = "Mumbai";
String useraddress = "Address";
int year = Calendar.getInstance().get(Calendar.YEAR);

String userDOJ = "01-09-2016";
String userEndDate = "31/03/2019";
String userWorkingLocation = "Delhi";
String userWorkingPlace = "Delhi";
String userAnnual_Income_Rs = "20000";
String userAnnual_Income_Words = "Twenty Thousand";
String userhis_her = "";
String userhe_she = "";
String userhim_her = "";
String engagementType="Consultant";

if(usergender == "Male")
{
userinitial = "Mr.";
userhis_her = "his";
userhe_she = "he";
userhim_her = "him";
}
else if(usergender == "Female")
{
userinitial= "Ms.";
userhis_her = "her";
userhe_she = "she";
userhim_her = "her";
}
else
{
userinitial="Mr./Ms.";
userhis_her = "his/her";
userhe_she = "he/she";
userhim_her = "him/her";
}

//Write the Document in file system
FileOutputStream out = new FileOutputStream(year + "_" + username + "_" + "Appointment_Letter_"+engagementType +".docx");
//Blank Document
XWPFDocument document = new XWPFDocument();
//create Paragraph
XWPFParagraph paragraph = document.createParagraph();
CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();

XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);

//----------------------- Add Header ---------------------------------------------------------

CTP ctpHeader = CTP.Factory.newInstance();
CTP ctpFooter = CTP.Factory.newInstance();

String HeaderText = "XYZ";
XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, document);
XWPFRun headerRun= headerParagraph.createRun();

headerRun.setBold(true);
headerRun.setFontSize(18);
headerRun.setColor("000000");
headerParagraph.setAlignment(ParagraphAlignment.LEFT);
headerParagraph.setBorderBottom(Borders.BASIC_BLACK_DASHES);

headerParagraph.setSpacingAfter(0);
headerParagraph.setSpacingBefore(0);

headerRun.addBreak();
String HeaderText1 = "Delhi Office:";
headerRun= headerParagraph.createRun();
headerParagraph = new XWPFParagraph(ctpHeader, document);
headerRun.setFontSize(9);
headerRun.setColor("000000");
headerRun.setText(HeaderText1);

headerRun.addBreak();
String HeaderText2 = "Phone Number: +91-11-26716083, +91-11-41651638";
headerRun= headerParagraph.createRun();
headerParagraph = new XWPFParagraph(ctpHeader, document);
headerRun.setFontSize(9);
headerRun.setColor("000000");
headerRun.setText(HeaderText2);
headerRun.addTab();

XWPFParagraph[] parsHeader = new XWPFParagraph[1];
parsHeader[0] = headerParagraph;

policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);

//----------------------- Add Footer ---------------------------------------------------------

String FooterText1 = "Address 1";
XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, document);
XWPFRun footerRun= footerParagraph.createRun();
footerRun= footerParagraph.createRun();
footerParagraph = new XWPFParagraph(ctpFooter, document);
footerRun.setFontSize(9);
footerRun.setColor("000000");
footerRun.setText(FooterText1);
footerParagraph.setAlignment(ParagraphAlignment.CENTER);
footerParagraph.setBorderTop(Borders.BASIC_BLACK_DASHES);

footerRun.addBreak();
String FooterText2 = "Phone Number: +91-22-/62 Fax : +9122-E-mail : i";
footerRun= footerParagraph.createRun();
footerParagraph = new XWPFParagraph(ctpFooter, document);
footerRun.setFontSize(9);
footerRun.setColor("000000");
footerRun.setText(FooterText2);

footerRun.addBreak();
String FooterText3 = "A company registered u/s 8 of the Companies Act 2013 Incorporation No. ";
footerRun= footerParagraph.createRun();
footerParagraph = new XWPFParagraph(ctpFooter, document);
footerRun.setFontSize(9);
footerRun.setColor("000000");
footerRun.setText(FooterText3);

XWPFParagraph[] parsFooter = new XWPFParagraph[1];
parsFooter[0] = footerParagraph;

policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);

//----------------------- BODY ---------------------------------------------------------

XWPFRun p1 = paragraph.createRun();
p1.setBold(true);
p1.setFontSize(11);
p1.setText(" LETTER OF CONTRACT");
p1.addBreak();
p1.addBreak();

//Set Bold
XWPFRun p2 = paragraph.createRun();
p2.setBold(true);
p2.setFontSize(11);
p2.setText("Service Contract No.: XYZ/" + userstate + "/SC/2018-19/«S_No»");
p2.addBreak();
p2.addBreak();

//Set Heading Bold Underscore
XWPFRun p3 = paragraph.createRun();
p3.setFontSize(11);
p3.setText("MEMORANDUM OF CONTRACT made on " + todaysdate + " betweenXYZ (hereinafter referred to as XYZ), a section 8 company registered under Companies Act, 2013 and " + userinitial + " " + userfullname + " (hereinafter referred to as the Consultant) whose address is: " + useraddress + " having Pan: " + userpancard + ".");
p3.addBreak();
p3.addBreak();

XWPFRun p4 = paragraph.createRun();
p4.setFontSize(11);
p4.setText("NOW, therefore in consideration of the mutual covenants, terms & conditions set forth herein, XYZ and the consultant agree as follows:");
p4.addBreak();
p4.addBreak();

XWPFRun p5 = paragraph.createRun();
p5.setBold(true);
p5.setFontSize(11);
p5.setText("1. DURATION OF THE CONTRACT");
p5.addBreak();
p5.addBreak();

XWPFRun p51 = paragraph.createRun();
p51.setFontSize(11);
p51.setText("This contract will come into effect on "+ userDOJ +" and expire on "+ userEndDate +".");
p51.addBreak();
p51.addBreak();

XWPFRun p6 = paragraph.createRun();
p6.setBold(true);
p6.setFontSize(11);
p6.setText("2. TERMS OF REFERENCE");
p6.addBreak();
p6.addBreak();

XWPFRun p61 = paragraph.createRun();
p61.setFontSize(11);
p61.setText("The consultant agrees to the terms of reference as set forth in Annex A to this contract. The consultant will be based in "+ userWorkingLocation +", "+ userWorkingPlace +" and for operational purposes may be assigned a designation, "+ userdesignation +" with PEF. However, PEF reserves the right to transfer the Consultant as and when necessary with in India.");
p61.addBreak();
p61.addBreak();

XWPFRun p7 = paragraph.createRun();
p7.setBold(true);
p7.setFontSize(11);
p7.setText("3. CONSULTANCY FEE");
p7.addBreak();
p7.addBreak();

XWPFRun p71 = paragraph.createRun();
p71.setFontSize(11);
p71.setText("As full consideration for the services performed by the consultant under the terms of this contract XYZwill pay an amount of Rs. "+ userAnnual_Income_Rs +" /-( " + userAnnual_Income_Words + " Only ) during the contract period in monthly installments. No other remuneration, compensation, subsidy will be paid under this contract. However, in case of official travel, the actual expenses incurred will be reimbursed separately as per the applicable guidelines of XYZ.");
p71.addBreak();
p71.addBreak();

XWPFRun p8 = paragraph.createRun();
p8.setBold(true);
p8.setFontSize(11);
p8.setText("4. INCOME TAX - TAX DEDUCTED AT SOURCE (TDS)");
p8.addBreak();
p8.addBreak();

XWPFRun p81 = paragraph.createRun();
p81.setFontSize(11);
p81.setText("TDS will be deducted on the gross monthly consultancy fee made to the consultant as per the provisions given in Income Tax Act, 1961.");
p81.addBreak();
p81.addBreak();


XWPFRun p122 = paragraph.createRun();
p122.setFontSize(11);
p122.setText("The Consultant acknowledges and admits that "+ userhe_she +" has been made aware of, carefully read and understood the details of this contract along with its annexure and XYZ’s various policies including policy against sexual harassment, child protection policy, fraud policy, etc. and has got the same translated and explained to " + userhim_her + " in " + userhis_her + " vernacular language by XYZand by independent sources. "+ userhe_she +" agrees that during the course of " + userhis_her + " consultancy, all new policies and modifications in existing policies shall apply to "+ userhis_her +" services.");
p122.addBreak();
p122.addBreak();
p122.addBreak();

XWPFRun p13 = paragraph.createRun();
p13.setFontSize(11);
p13.setText("By: __________________ By: __________________________");
p13.addBreak();
p13.addBreak();
p13.addBreak();
p13.addBreak();

XWPFRun p14 = paragraph.createRun();
p14.setFontSize(11);
p14.setText("(On behalf of the XYZ) (Consultant’s Signature)");
p14.addBreak();

XWPFRun p15 = paragraph.createRun();
p15.setFontSize(11);
p15.setText(" Annexure A to the Service Contract");
p15.addBreak();

XWPFRun p16 = paragraph.createRun();
p16.setFontSize(11);
p16.setBold(true);
p16.setText(" TERMS OF REFERENCE");
p16.addBreak();
p16.addBreak();

XWPFRun p17 = paragraph.createRun();
p17.setFontSize(11);
p17.setText("The following is a summary outline of the main conditions of service under the Service Contract No: XYZ/"+ userstate +"/SC/2018-19/«S_No» .");
p17.addBreak();

XWPFRun p18 = paragraph.createRun();
p18.setBold(true);
p18.setFontSize(11);
p18.setText("1. Status");
p18.addBreak();

XWPFRun p181 = paragraph.createRun();
p181.setFontSize(11);
p181.setText("The Consultant is not a staff member of the XYZ. The Consultant has been contracted on a work for hire basis. The Consultant may be given the status of ‘expert on project’. In such event, the Consultant will be considered to have functional immunity as required to perform "+ userhis_her +" contractual obligations, in terms of words spoken or written and acts done, in direct compliance with "+ userhis_her +" official duties.");
p181.addBreak();
p181.addBreak();

XWPFRun p19 = paragraph.createRun();
p19.setBold(true);
p19.setFontSize(11);
p19.setText("2. Consultancy Fee");
p19.addBreak();

XWPFRun p191 = paragraph.createRun();
p191.setFontSize(11);
p191.setText("Fee is expressed and payable in a lump sum each month. It is established on the basis of the level of responsibility of the assignment, and the experience and competencies of the individual engaged.");
p191.addBreak();
p191.addBreak();

XWPFRun p223 = paragraph.createRun();
p223.setBold(true);
p223.setFontSize(11);
p223.setText("Consultant’s signature: ____________________________");
p223.addBreak();

XWPFRun p224 = paragraph.createRun();
p224.setBold(true);
p224.setFontSize(11);
p224.setText("Date: ___________________");



document.write(out);
out.close();
}
catch(Exception e) {
System.out.println(e);
}
System.out.println("createparagraph.docx written successfully");
}
}

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Thank you for Help.

      But Currently I got below issue

       

      java.lang.NoClassDefFoundError: org/apache/poi/wp/usermodel/Paragraph

       

       

        CommentAdd your comment...
      1.  
        1
        0
        -1

        You can try to develop a process tool plugin - check out the tutorial for How to develop a Download PDF Datalist Action 

        If it is simple enough, you can just put your code into Bean Shell for Process Tool

          CommentAdd your comment...