Example usage for org.apache.poi.xwpf.usermodel XWPFRun setUnderline

List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setUnderline

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFRun setUnderline.

Prototype

public void setUnderline(UnderlinePatterns value) 

Source Link

Document

Specifies that the contents of this run should be displayed along with an underline appearing directly below the character height.

Usage

From source file:ch.admin.searchreplace.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);/*www . j  av  a 2s .  co  m*/
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    // BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    // p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    // This would imply that this break shall be treated as a simple line break, and break the line after that
    // word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("simple.docx");
    doc.write(out);
    out.close();

}

From source file:com.crimelab.service.PolygraphServiceImpl.java

@Override
public XWPFDocument create(Polygraph polygraph, HttpSession session) {
    XWPFDocument document = null;/*from   w w  w. j a v a  2  s.c  o  m*/

    //Insert into dbase
    //        polygraphDAO.polygraphInfo(polygraph);
    try {
        //Blank Document
        InputStream inpDocx = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/Polygraph.docx");
        document = new XWPFDocument(inpDocx);

        //create Paragraph
        XWPFParagraph subjectNo = document.createParagraph();
        XWPFRun r1 = subjectNo.createRun();
        r1.setText("POLYGRAPH SUBJECT NO: " + polygraph.getSubjectNo());
        subjectNo.setAlignment(ParagraphAlignment.CENTER);
        r1.setBold(true);
        ;

        //create table
        XWPFTable table = document.createTable();
        //width 
        CTTbl tableFix = table.getCTTbl();
        CTTblPr pr = tableFix.getTblPr();
        CTTblWidth tblW = pr.getTblW();
        tblW.setW(BigInteger.valueOf(4800));
        tblW.setType(STTblWidth.PCT);
        pr.setTblW(tblW);
        tableFix.setTblPr(pr);

        //create first row
        XWPFTableRow tableRowOne = table.getRow(0);
        XWPFTableCell headerCell = tableRowOne.getCell(0);
        XWPFParagraph headerParagraph = headerCell.getParagraphs().get(0);
        XWPFRun hRun = headerParagraph.createRun();
        headerCell.setColor("CDCDB4");
        hRun.setText("PERSONAL INFORMATION");
        tableRowOne.addNewTableCell().setText(null);

        headerParagraph.setAlignment(ParagraphAlignment.CENTER);
        XWPFTableCell photoHeaderCell = tableRowOne.getCell(1);
        XWPFParagraph photoHeaderParagraph = photoHeaderCell.getParagraphs().get(0);
        XWPFRun pRun = photoHeaderParagraph.createRun();
        photoHeaderCell.setColor("CDCDB4");
        pRun.setText("PHOTO");
        photoHeaderParagraph.setAlignment(ParagraphAlignment.CENTER);

        XWPFTableRow tableRowTwo = table.createRow();
        XWPFTableCell cell = tableRowTwo.getCell(0);
        XWPFParagraph personalInfo = cell.getParagraphs().get(0);
        XWPFRun r2 = personalInfo.createRun();
        r2.setText("Name");
        r2.addTab();
        r2.addTab();
        r2.setText(": " + polygraph.getName());
        r2.addBreak();
        r2.setText("Gender");
        r2.addTab();
        r2.addTab();
        r2.setText(": " + polygraph.getGender());
        r2.addBreak();
        r2.setText("Age");
        r2.addTab();
        r2.addTab();
        r2.setText(": " + polygraph.getAge());
        r2.addBreak();
        r2.setText("Date of Birth");
        r2.addTab();
        r2.setText(": " + polygraph.getBirthdate());
        r2.addBreak();
        r2.setText("Civil Status");
        r2.addTab();
        r2.setText(": " + polygraph.getCivilStatus());
        r2.addBreak();
        r2.setText("ID Presented");
        r2.addTab();
        r2.setText(": " + polygraph.getIdPresented());
        r2.addBreak();
        r2.setText("Address");
        r2.addTab();
        r2.setText(": " + polygraph.getAddress());

        //Adding the picture
        XWPFTableCell pictureCell = tableRowTwo.getCell(1);
        XWPFParagraph pictureHolder = pictureCell.getParagraphs().get(0);
        XWPFRun pictureRun = pictureHolder.createRun();
        FileInputStream getPhoto = new FileInputStream(polygraph.getPhotoLocation());
        FileInputStream getImage = new FileInputStream(polygraph.getPhotoLocation());
        ImageInputStream imageInput = ImageIO.createImageInputStream(getPhoto);
        BufferedImage bi = ImageIO.read(imageInput);
        pictureHolder.setAlignment(ParagraphAlignment.RIGHT);
        pictureRun.addPicture(getImage, XWPFDocument.PICTURE_TYPE_JPEG, null, Units.toEMU(120),
                Units.toEMU(120));

        XWPFParagraph spacing = document.createParagraph();
        XWPFRun spacingRun = spacing.createRun();

        //create table
        XWPFTable otherTable = document.createTable();
        //width 
        CTTbl tableFixTwo = otherTable.getCTTbl();
        CTTblPr prTwo = tableFixTwo.getTblPr();
        CTTblWidth tblWTwo = prTwo.getTblW();
        tblWTwo.setW(BigInteger.valueOf(4800));
        tblWTwo.setType(STTblWidth.PCT);
        prTwo.setTblW(tblWTwo);
        tableFixTwo.setTblPr(prTwo);

        XWPFTableRow examInfoHeader = otherTable.createRow();
        XWPFTableCell cellInfo = examInfoHeader.getCell(0);
        XWPFParagraph examInfo = cellInfo.getParagraphs().get(0);
        XWPFRun r3 = examInfo.createRun();
        cellInfo.setColor("CDCDB4");
        r3.setText("EXAM INFORMATION");
        examInfo.setAlignment(ParagraphAlignment.CENTER);

        XWPFTableRow examInfoRow = otherTable.createRow();
        XWPFTableCell cellRowInfo = examInfoRow.getCell(0);
        XWPFParagraph examInfoRowP = cellRowInfo.getParagraphs().get(0);
        XWPFRun examRun = examInfoRowP.createRun();
        examRun.setText("Case Number");
        examRun.addTab();
        examRun.addTab();
        examRun.setText(": " + polygraph.getCaseNo());
        examRun.addBreak();
        examRun.setText("Requesting Party");
        examRun.addTab();
        examRun.setText(": " + polygraph.getRequestingParty());
        examRun.addBreak();
        examRun.setText("Time/Date Received");
        examRun.addTab();
        examRun.setText(": " + polygraph.getTimeDateReceived());
        examRun.addBreak();
        examRun.setText("Nature of Case");
        examRun.addTab();
        examRun.addTab();
        examRun.setText(": " + polygraph.getNatureOfCase());
        examRun.addBreak();
        examRun.setText("Exam Location");
        examRun.addTab();
        examRun.addTab();
        examRun.setText(": " + polygraph.getExamLocation());
        examRun.addBreak();
        examRun.setText("Exam Date");
        examRun.addTab();
        examRun.addTab();
        examRun.setText(": " + polygraph.getExamDate());

        otherTable.removeRow(0);

        XWPFParagraph purposeOfExamination = document.createParagraph();
        XWPFRun r4 = purposeOfExamination.createRun();
        r4.setUnderline(UnderlinePatterns.SINGLE);
        r4.addBreak();
        r4.setText("SECTION 1: PURPOSE OF EXAMINATION");
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();
        r4.addTab();

        XWPFParagraph purposeOfExaminationContents = document.createParagraph();
        XWPFRun r4Contents = purposeOfExaminationContents.createRun();
        r4Contents.setText(polygraph.getPurpose());

        XWPFParagraph preTestInterview = document.createParagraph();
        XWPFRun r5 = preTestInterview.createRun();
        r5.setUnderline(UnderlinePatterns.SINGLE);
        r5.setText("SECTION 2: PRE-TEST INTERVIEW");
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();
        r5.addTab();

        XWPFParagraph preTestInterviewContents = document.createParagraph();
        XWPFRun r5Contents = preTestInterviewContents.createRun();
        r5Contents.setText(polygraph.getPreTest());

        XWPFParagraph inTestPhase = document.createParagraph();
        XWPFRun r6 = inTestPhase.createRun();
        r6.setUnderline(UnderlinePatterns.SINGLE);
        r6.setText("SECTION 3: IN-TEST PHASE");
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();
        r6.addTab();

        XWPFParagraph inTestPhaseContents = document.createParagraph();
        XWPFRun r6Contents = inTestPhaseContents.createRun();
        r6Contents.setText(polygraph.getInTest());

        XWPFParagraph result = document.createParagraph();
        XWPFRun r7 = result.createRun();
        r7.setUnderline(UnderlinePatterns.SINGLE);
        r7.setText("SECTION 4: RESULT");
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();
        r7.addTab();

        XWPFParagraph resultContents = document.createParagraph();
        XWPFRun r7Contents = resultContents.createRun();
        r7Contents.setText(polygraph.getResult());

        XWPFParagraph postTestInterview = document.createParagraph();
        XWPFRun r8 = postTestInterview.createRun();
        r8.setUnderline(UnderlinePatterns.SINGLE);
        r8.setText("SECTION 5: POST-TEST INTERVIEW");
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();
        r8.addTab();

        XWPFParagraph postTestInterviewContents = document.createParagraph();
        XWPFRun r8Contents = postTestInterviewContents.createRun();
        r8Contents.setText(polygraph.getPostTest());

        XWPFParagraph remarks = document.createParagraph();
        XWPFRun r9 = remarks.createRun();
        r9.setUnderline(UnderlinePatterns.SINGLE);
        r9.setText("REMARKS:");
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();
        r9.addTab();

        XWPFParagraph remarksContents = document.createParagraph();
        XWPFRun r9Contents = remarksContents.createRun();
        r9Contents.setText(polygraph.getRemarks());

        XWPFParagraph timeDateCompleted = document.createParagraph();
        XWPFRun r10 = timeDateCompleted.createRun();
        r10.setUnderline(UnderlinePatterns.SINGLE);
        r10.setText("TIME AND DATE COMPLETED:");
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();
        r10.addTab();

        XWPFParagraph timeDateCompletedContents = document.createParagraph();
        XWPFRun r10Contents = timeDateCompletedContents.createRun();
        r10Contents.setText(polygraph.getTimeDateCompleted());

        XWPFParagraph examinedBy = document.createParagraph();
        XWPFRun r11 = examinedBy.createRun();
        r11.setUnderline(UnderlinePatterns.SINGLE);
        r11.setText("EXAMINED BY:");
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();
        r11.addTab();

        XWPFParagraph examinedByContents = document.createParagraph();
        XWPFRun r11Contents = examinedByContents.createRun();
        r11Contents.setText(polygraph.getExaminerName());
        r11Contents.addBreak();
        r11Contents.setText(polygraph.getExaminerRank());
        r11Contents.addBreak();
        r11Contents.setText(polygraph.getExaminerPosition());

        XWPFParagraph approvedBy = document.createParagraph();
        XWPFRun r12 = approvedBy.createRun();
        r12.setUnderline(UnderlinePatterns.SINGLE);
        r12.setText("APPROVED BY:");
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();
        r12.addTab();

        XWPFParagraph approvedByContents = document.createParagraph();
        XWPFRun r12Contents = approvedByContents.createRun();
        //            r12Contents.setText(polygraph.getApprovedName());
        //            r12Contents.addBreak();
        //            r12Contents.setText(polygraph.getApprovedRank());
        //            r12Contents.addBreak();
        //            r12Contents.setText(polygraph.getApprovedPosition());
        //            r12Contents.addBreak();

        XWPFParagraph notedBy = document.createParagraph();
        XWPFRun r13 = notedBy.createRun();
        r13.setUnderline(UnderlinePatterns.SINGLE);
        r13.setText("NOTED BY:");
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();
        r13.addTab();

        XWPFParagraph notedByContents = document.createParagraph();
        XWPFRun r13Contents = notedByContents.createRun();
        r13Contents.setText(polygraph.getNotedName());
        r13Contents.addBreak();
        r13Contents.setText(polygraph.getNotedRank());
        r13Contents.addBreak();
        r13Contents.setText(polygraph.getNotedPosition());
        r13Contents.addBreak();
        table.setInsideVBorder(XWPFTable.XWPFBorderType.NIL, 0, 0, "white");

        document.getXWPFDocument();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return document;
}

From source file:com.deepoove.poi.resolver.TemplateResolver.java

License:Apache License

private static void styleRun(XWPFRun destRun, XWPFRun srcRun) {
    if (null == destRun || null == srcRun)
        return;//from w  w w . j a va2s  .co  m
    destRun.setBold(srcRun.isBold());
    destRun.setColor(srcRun.getColor());
    destRun.setFontFamily(srcRun.getFontFamily());
    int fontSize = srcRun.getFontSize();
    if (-1 != fontSize)
        destRun.setFontSize(fontSize);
    destRun.setItalic(srcRun.isItalic());
    destRun.setStrike(srcRun.isStrike());
    destRun.setUnderline(srcRun.getUnderline());
}

From source file:com.deepoove.poi.tl.SimpleTable.java

License:Apache License

public static void createSimpleTable() throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFTable table = doc.createTable(3, 3);

    table.getRow(1).getCell(1).setText("EXAMPLE OF TABLE");

    // table cells have a list of paragraphs; there is an initial
    // paragraph created when the cell is created. If you create a
    // paragraph in the document to put in the cell, it will also
    // appear in the document following the table, which is probably
    // not the desired result.
    XWPFParagraph p1 = table.getRow(0).getCell(0).getParagraphs().get(0);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);//from  w w  w .j a va 2  s.  c  om
    r1.setText("The quick brown fox");
    r1.setItalic(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    table.getRow(2).getCell(2).setText("only text");

    FileOutputStream out = new FileOutputStream("simpleTable.docx");
    doc.write(out);
    out.close();
}

From source file:com.dexter.fms.mbean.FleetMBean.java

License:Open Source License

@SuppressWarnings("unchecked")
public void generateWorkOrderWordDoc(long id) {
    try {// www .  java2  s. c o  m
        setSelectedWorkOrder(null);
        for (WorkOrder w : getRountineWorkOrders()) {
            if (w.getId().longValue() == id) {
                setSelectedWorkOrder(w);
                break;
            }
        }

        if (getSelectedWorkOrder() != null) {
            GeneralDAO gDAO = new GeneralDAO();

            FacesContext context = FacesContext.getCurrentInstance();
            XWPFDocument document = new XWPFDocument();

            XWPFParagraph paragraphOne = document.createParagraph();
            paragraphOne.setAlignment(ParagraphAlignment.LEFT);
            /*paragraphOne.setBorderBottom(Borders.SINGLE);
            paragraphOne.setBorderTop(Borders.SINGLE);
            paragraphOne.setBorderRight(Borders.SINGLE);
            paragraphOne.setBorderLeft(Borders.SINGLE);
            paragraphOne.setBorderBetween(Borders.SINGLE);
            */
            XWPFRun paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Work Order No. - " + getSelectedWorkOrder().getWorkOrderNumber());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Type - " + getSelectedWorkOrder().getWorkOrderType());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText(
                    "Prepared by - " + getSelectedWorkOrder().getCreatedBy().getPersonel().getFirstname() + " "
                            + getSelectedWorkOrder().getCreatedBy().getPersonel().getLastname());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Prepared on - " + getSelectedWorkOrder().getCrt_dt());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne
                    .setText("Description - " + getSelectedWorkOrder().getSummaryDetailsOfWorkOrder());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Status - " + getSelectedWorkOrder().getStatus());
            paragraphOneRunOne.addBreak();

            if ((getSelectedWorkOrder().getStatus().equalsIgnoreCase("IN-PROGRESS")
                    || getSelectedWorkOrder().getStatus().equalsIgnoreCase("COMPLETED"))) {
                paragraphOneRunOne = paragraphOne.createRun();
                paragraphOneRunOne.setBold(true);
                paragraphOneRunOne.setItalic(true);
                if (getSelectedWorkOrder().getVendor() != null)
                    paragraphOneRunOne.setText("Vendor - " + getSelectedWorkOrder().getVendor().getName());
                else
                    paragraphOneRunOne.setText("Vendor - N/A");
                paragraphOneRunOne.addBreak();
            }

            XWPFParagraph paragraph2 = document.createParagraph();
            paragraph2.setAlignment(ParagraphAlignment.CENTER);
            XWPFRun paragraph2Run = paragraph2.createRun();
            paragraph2Run.setBold(true);
            paragraph2Run.setItalic(true);
            paragraph2Run.setUnderline(UnderlinePatterns.DOUBLE);
            paragraph2Run.setText("Vehicles");
            paragraph2Run.addBreak();

            double totalCost = 0;
            for (WorkOrderVehicle v : getSelectedWorkOrder().getVehicles()) {
                VehicleRoutineMaintenance vrm = null;
                if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("IN-PROGRESS")
                        || getSelectedWorkOrder().getStatus().equalsIgnoreCase("COMPLETED")) {
                    Hashtable<String, Object> params = new Hashtable<String, Object>();
                    params.put("vehicle", v.getVehicle());
                    params.put("workOrder", getSelectedWorkOrder());

                    Object vrmObj = gDAO.search("VehicleRoutineMaintenance", params);
                    if (vrmObj != null) {
                        Vector<VehicleRoutineMaintenance> list = (Vector<VehicleRoutineMaintenance>) vrmObj;
                        vrm = list.get(0);
                    }
                }

                XWPFParagraph paragraph = document.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                XWPFRun paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Registration Number: " + v.getVehicle().getRegistrationNo());
                paragraphRun.addBreak();

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Model: " + v.getVehicle().getModel().getName() + "["
                        + v.getVehicle().getModel().getYear() + "]");
                paragraphRun.addBreak();

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Work Required: " + v.getDetailsOfWork());
                paragraphRun.addBreak();

                if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("IN-PROGRESS") && vrm != null) {
                    paragraphRun = paragraph.createRun();
                    paragraphRun.setBold(true);
                    paragraphRun.setItalic(true);
                    paragraphRun.setText("Start Date: " + vrm.getStart_dt());
                    paragraphRun.addBreak();
                } else if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("COMPLETED") && vrm != null) {
                    paragraphRun = paragraph.createRun();
                    paragraphRun.setBold(true);
                    paragraphRun.setItalic(true);
                    paragraphRun.setText("Start Date: " + vrm.getStart_dt());
                    paragraphRun.addBreak();

                    paragraphRun = paragraph.createRun();
                    paragraphRun.setBold(true);
                    paragraphRun.setItalic(true);
                    paragraphRun.setText("Close Date: " + vrm.getClose_dt());
                    paragraphRun.addBreak();
                }

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("NEW"))
                    paragraphRun.setText("Vendor Cost: ");
                else if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("IN-PROGRESS")) {
                    if (vrm != null) {
                        paragraphRun.setText("Vendor Cost: "
                                + NumberFormat.getInstance().format(vrm.getInitial_amount().doubleValue()));
                        totalCost += vrm.getInitial_amount().doubleValue();
                    } else
                        paragraphRun.setText("Vendor Cost: ");
                } else if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("COMPLETED")) {
                    if (vrm != null) {
                        paragraphRun.setText("Vendor Cost: "
                                + NumberFormat.getInstance().format(vrm.getClosed_amount().doubleValue()));
                        totalCost += vrm.getClosed_amount().doubleValue();
                    } else
                        paragraphRun.setText("Vendor Cost: ");
                }
                paragraphRun.addBreak();

                XWPFTable table = paragraph.getDocument().createTable();
                XWPFTableRow tableRowOne = table.getRow(0);
                addHeaderCell(tableRowOne, "Item", true);
                addHeaderCell(tableRowOne, "Type", false);
                addHeaderCell(tableRowOne, "Action", false);
                addHeaderCell(tableRowOne, "Count", false);

                if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("NEW")) {
                    addHeaderCell(tableRowOne, "Vendor Cost", false);
                    addHeaderCell(tableRowOne, "Comment", false);
                }

                for (WorkOrderItem itm : v.getItems()) {
                    XWPFTableRow tableRow = table.createRow();
                    tableRow.getCell(0).setText(itm.getItem().getName());
                    tableRow.getCell(1).setText(itm.getItem().getType().getName());
                    tableRow.getCell(2).setText(itm.getAction());
                    tableRow.getCell(3).setText(String.valueOf(itm.getCount()));
                    if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("NEW")) {
                        tableRow.getCell(4).setText("");
                        tableRow.getCell(5).setText("");
                    }
                }
            }
            gDAO.destroy();

            if (getSelectedWorkOrder().getStatus().equalsIgnoreCase("IN-PROGRESS")
                    || getSelectedWorkOrder().getStatus().equalsIgnoreCase("COMPLETED")) {
                XWPFParagraph paragraph = document.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                XWPFRun paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Total Cost: " + NumberFormat.getInstance().format(totalCost));
            }

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            document.write(baos);

            String fileName = getSelectedWorkOrder().getWorkOrderNumber() + ".docx";

            writeFileToResponse(context.getExternalContext(), baos, fileName,
                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

            context.responseComplete();
        } else {
            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Failed: ", "No work order selected!");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR: ", ex.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

From source file:com.dexter.fms.mbean.FleetMBean.java

License:Open Source License

private byte[] generateWorkOrderWordDoc(WorkOrder workder, Vendor vendor) {
    byte[] data = null;
    try {//from   www .  ja v a 2  s. c o m
        if (workder != null) {
            GeneralDAO gDAO = new GeneralDAO();

            XWPFDocument document = new XWPFDocument();

            XWPFParagraph paragraphOne = document.createParagraph();
            paragraphOne.setAlignment(ParagraphAlignment.LEFT);
            /*paragraphOne.setBorderBottom(Borders.SINGLE);
            paragraphOne.setBorderTop(Borders.SINGLE);
            paragraphOne.setBorderRight(Borders.SINGLE);
            paragraphOne.setBorderLeft(Borders.SINGLE);
            paragraphOne.setBorderBetween(Borders.SINGLE);
            */
            XWPFRun paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Work Order No. - " + workder.getWorkOrderNumber());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Type - " + workder.getWorkOrderType());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Prepared by - " + workder.getCreatedBy().getPersonel().getFirstname()
                    + " " + workder.getCreatedBy().getPersonel().getLastname());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Prepared on - " + workder.getCrt_dt());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Description - " + workder.getSummaryDetailsOfWorkOrder());
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Status - BIDDING");
            paragraphOneRunOne.addBreak();

            paragraphOneRunOne = paragraphOne.createRun();
            paragraphOneRunOne.setBold(true);
            paragraphOneRunOne.setItalic(true);
            paragraphOneRunOne.setText("Vendor - " + vendor.getName());
            paragraphOneRunOne.addBreak();

            XWPFParagraph paragraph2 = document.createParagraph();
            paragraph2.setAlignment(ParagraphAlignment.CENTER);
            XWPFRun paragraph2Run = paragraph2.createRun();
            paragraph2Run.setBold(true);
            paragraph2Run.setItalic(true);
            paragraph2Run.setUnderline(UnderlinePatterns.DOUBLE);
            paragraph2Run.setText("Vehicles");
            paragraph2Run.addBreak();

            for (WorkOrderVehicle v : workder.getVehicles()) {
                XWPFParagraph paragraph = document.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                XWPFRun paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Registration Number: " + v.getVehicle().getRegistrationNo());
                paragraphRun.addBreak();

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Model: " + v.getVehicle().getModel().getName() + "["
                        + v.getVehicle().getModel().getYear() + "]");
                paragraphRun.addBreak();

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Work Required: " + v.getDetailsOfWork());
                paragraphRun.addBreak();

                paragraphRun = paragraph.createRun();
                paragraphRun.setBold(true);
                paragraphRun.setItalic(true);
                paragraphRun.setText("Vendor Cost: <please fill your cost here>");
                paragraphRun.addBreak();

                XWPFTable table = paragraph.getDocument().createTable();
                XWPFTableRow tableRowOne = table.getRow(0);
                addHeaderCell(tableRowOne, "Item", true);
                addHeaderCell(tableRowOne, "Type", false);
                addHeaderCell(tableRowOne, "Action", false);
                addHeaderCell(tableRowOne, "Count", false);

                addHeaderCell(tableRowOne, "Vendor Cost", false);
                addHeaderCell(tableRowOne, "Comment", false);

                for (WorkOrderItem itm : v.getItems()) {
                    XWPFTableRow tableRow = table.createRow();
                    tableRow.getCell(0).setText(itm.getItem().getName());
                    tableRow.getCell(1).setText(itm.getItem().getType().getName());
                    tableRow.getCell(2).setText(itm.getAction());
                    tableRow.getCell(3).setText(String.valueOf(itm.getCount()));

                    tableRow.getCell(4).setText("");
                    tableRow.getCell(5).setText("");
                }
            }
            gDAO.destroy();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            document.write(baos);

            data = baos.toByteArray();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return data;
}

From source file:com.ecm.poi.SimpleDocument.java

License:Apache License

@Test
public void xwpfTest() throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);/*from  w w w.j a  v  a2 s  .c  o m*/
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    //BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    //This would imply that this break shall be treated as a simple line break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("d:\\temp\\simple.docx");
    doc.write(out);
    out.close();

}

From source file:com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout.java

License:Apache License

public static void fillWordDocument(XWPFDocument doc) {
    try {//from w ww  .jav a 2s  . c  o  m
        XWPFParagraph p1 = doc.createParagraph();
        p1.setAlignment(ParagraphAlignment.CENTER);
        p1.setBorderBottom(Borders.DOUBLE);
        p1.setBorderTop(Borders.DOUBLE);

        p1.setBorderRight(Borders.DOUBLE);
        p1.setBorderLeft(Borders.DOUBLE);
        p1.setBorderBetween(Borders.SINGLE);

        p1.setVerticalAlignment(TextAlignment.TOP);

        XWPFRun r1 = p1.createRun();
        r1.setBold(true);
        r1.setText("The quick brown fox");
        r1.setBold(true);
        r1.setFontFamily("Courier");
        r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
        r1.setTextPosition(100);

        XWPFParagraph p2 = doc.createParagraph();
        p2.setAlignment(ParagraphAlignment.RIGHT);

        //BORDERS
        p2.setBorderBottom(Borders.DOUBLE);
        p2.setBorderTop(Borders.DOUBLE);
        p2.setBorderRight(Borders.DOUBLE);
        p2.setBorderLeft(Borders.DOUBLE);
        p2.setBorderBetween(Borders.SINGLE);

        XWPFRun r2 = p2.createRun();
        r2.setText("jumped over the lazy dog");
        r2.setStrike(true);
        r2.setFontSize(20);

        XWPFRun r3 = p2.createRun();
        r3.setText("and went away");
        r3.setStrike(true);
        r3.setFontSize(20);
        r3.setSubscript(VerticalAlign.SUPERSCRIPT);

        XWPFParagraph p3 = doc.createParagraph();
        p3.setWordWrap(true);
        p3.setPageBreak(true);

        p3.setAlignment(ParagraphAlignment.BOTH);
        p3.setSpacingLineRule(LineSpacingRule.EXACT);

        p3.setIndentationFirstLine(600);

        XWPFRun r4 = p3.createRun();
        r4.setTextPosition(200);
        r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
                + "The slings and arrows of outrageous fortune, "
                + "Or to take arms against a sea of troubles, "
                + "And by opposing end them? To die: to sleep; ");
        r4.addBreak(BreakType.PAGE);
        r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
                + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
                + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
        r4.setItalic(true);

        //This would imply that this break shall be treated as a simple line break, and break the line after that word:

        XWPFRun r5 = p3.createRun();
        r5.setTextPosition(-10);
        r5.setText("For in that sleep of death what dreams may come");
        r5.addCarriageReturn();
        r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
                + "That makes calamity of so long life;");
        r5.addBreak();
        r5.setText("For who would bear the whips and scorns of time,"
                + "The oppressor's wrong, the proud man's contumely,");

        r5.addBreak(BreakClear.ALL);
        r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
                + ".......");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.foc.vaadin.gui.mswordGenerator.FocMSWordLabel.java

License:Apache License

private void applyStyleToFocWordLabel(XWPFRun run, XWPFParagraph paragraph) {
    FocXMLAttributes xmlAttributes = getXmlAttribute();
    if (xmlAttributes != null) {
        String style = xmlAttributes.getValue(FXML.ATT_STYLE);
        if (style != null && !style.isEmpty()) {
            StringTokenizer styleParsing = new StringTokenizer(style, ",");

            while (styleParsing.hasMoreTokens()) {
                String styleToken = styleParsing.nextToken();

                if (styleToken.equals(FXML.MS_STYLE_VAL_BOLD)) {
                    run.setBold(true);/*from   w  w  w .  j  a  va2 s  .  c  om*/
                } else if (styleToken.startsWith(FXML.MS_STYLE_VAL_FONT_SIZE)
                        && !styleToken.startsWith(FXML.MS_STYLE_VAL_FONT_FAMILY)) {
                    String fontSize = styleToken.substring(1, styleToken.length());
                    int size = 0;
                    try {
                        size = Integer.parseInt(fontSize);
                    } catch (Exception ex) {
                        Globals.logException(ex);
                    }
                    run.setFontSize(size);
                } else if (styleToken.equals(FXML.MS_STYLE_VAL_ITALIC)) {
                    run.setItalic(true);
                } else if (styleToken.equals(FXML.MS_STYLE_VAL_UNDERLINE)) {
                    run.setUnderline(UnderlinePatterns.DASH);
                } else if (styleToken.startsWith(FXML.MS_STYLE_VAL_FONT_FAMILY)) {
                    String fontfamily = styleToken.substring(styleToken.indexOf("-") + 1, styleToken.length());
                    run.setFontFamily(fontfamily);
                } else if (styleToken.equals(FXML.MS_STYLE_VAL_ALIGN_LEFT)) {
                    paragraph.setAlignment(ParagraphAlignment.LEFT);
                } else if (styleToken.equals(FXML.MS_STYLE_VAL_ALIGN_RIGHT)) {
                    paragraph.setAlignment(ParagraphAlignment.RIGHT);
                } else if (styleToken.equals(FXML.MS_STYLE_VAL_ALIGN_CENTER)) {
                    paragraph.setAlignment(ParagraphAlignment.CENTER);
                }
            }
        }
    }
}

From source file:com.gezipu360.cashier.bean.word.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);//from   ww  w . j  a  va  2s. c  o m
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    //BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    //This would imply that this break shall be treated as a simple line break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

    FileOutputStream out = new FileOutputStream("simple.docx");
    doc.write(out);
    out.close();

}