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

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

Introduction

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

Prototype

@Override
public void setBold(boolean value) 

Source Link

Document

Whether the bold property shall be applied to all non-complex script characters in the contents of this run when displayed in a document.

Usage

From source file:genrate_doc.java

void insert_title(XWPFDocument doc) {

    XWPFParagraph p1 = doc.createParagraph();

    p1.setAlignment(ParagraphAlignment.CENTER);

    /*//p1.setBorderBottom(Borders.DOUBLE);
    //p1.setBorderTop(Borders.DOUBLE);//w w w . java 2  s. c  om
            
    //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("HACKMAN:");
    r1.setBold(true);
    r1.setCapitalized(true);
    r1.setFontSize(35);
    r1.setFontFamily("Courier");
    //r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFRun r2 = p1.createRun();
    r2.setBold(true);
    r2.setText("yaay :) we did it \n (Hopefully :P)");
    r2.setBold(true);
    r2.setCapitalized(true);
    r2.setFontSize(25);
    r2.setFontFamily("Courier");
    //r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r2.setTextPosition(300);

}

From source file:AkashApplications.src.GenerateInvoice.java

public boolean printInvoice(boolean printCommand)
        throws FileNotFoundException, InvalidFormatException, IOException {

    XWPFDocument document = new XWPFDocument();
    CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
    CTPageMar pageMar = sectPr.addNewPgMar();
    pageMar.setLeft(BigInteger.valueOf(720L));
    pageMar.setTop(BigInteger.valueOf(460L));
    pageMar.setRight(BigInteger.valueOf(720L));
    pageMar.setBottom(BigInteger.valueOf(460L));

    XWPFParagraph dateP = document.createParagraph();
    XWPFRun dateRun = dateP.createRun();
    dateRun.addBreak();/*from   w w  w  .  jav a2  s  .  com*/
    dateRun.setText(copyType);
    dateRun.setFontSize(8);
    dateRun.setItalic(true);
    dateP.setAlignment(ParagraphAlignment.RIGHT);
    dateRun.addBreak();

    XWPFParagraph title = document.createParagraph();
    XWPFRun titleRun = title.createRun();
    titleRun.addBreak();
    titleRun.setText("Delivery Challan");
    titleRun.setBold(true);
    title.setAlignment(ParagraphAlignment.CENTER);
    titleRun.addBreak();

    //header table
    XWPFTable productTable = document.createTable();
    productTable.setCellMargins(50, 50, 50, 50);
    productTable.getCTTbl().getTblPr().unsetTblBorders();
    productTable.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(11000));

    XWPFTableRow row1 = productTable.getRow(0);

    XWPFTableCell cellSellerBuyer = row1.getCell(0);
    cellSellerBuyer.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(5000));

    CTTc ctTc = cellSellerBuyer.getCTTc();
    CTTcPr tcPr = ctTc.getTcPr();
    CTTcBorders border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    //        border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    XWPFParagraph seller = cellSellerBuyer.addParagraph();
    XWPFRun sellerRun = seller.createRun();
    seller.setAlignment(ParagraphAlignment.LEFT);
    sellerRun.setText("Buyer :");
    sellerRun.addBreak();
    String[] ar = buyerAddress.split("\n");
    for (String s : ar) {
        sellerRun.setText(s);
        sellerRun.addBreak();
    }

    XWPFTableCell cellProductDesc = row1.createCell();
    cellProductDesc.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(6000));

    ctTc = cellProductDesc.getCTTc();
    tcPr = ctTc.getTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    //border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    XWPFParagraph productDesc = cellProductDesc.addParagraph();
    productDesc.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun runInvoice = productDesc.createRun();

    //        if(table.getRowCount() == 1)
    //        {
    //            runInvoice.addTab();
    //            runInvoice.addTab();
    //            runInvoice.addTab();
    //            String imgLoc = "Barcodes/"+ dtm.getValueAt(0, 6) +".jpg";
    //            FileInputStream image = new FileInputStream(imgLoc);
    //            runInvoice.addPicture(image, XWPFDocument.PICTURE_TYPE_JPEG,imgLoc, Units.toEMU(200), Units.toEMU(50));
    //            runInvoice.addBreak();
    //            runInvoice.addBreak();
    //        }

    runInvoice.setText("Delivery Note : ");
    runInvoice.addTab();
    runInvoice.setText(invoiceNote);
    runInvoice.addBreak();
    runInvoice.addBreak();
    runInvoice.addBreak();
    runInvoice.setText("Date : ");
    runInvoice.addTab();
    runInvoice.setText(date);
    runInvoice.addBreak();
    runInvoice.addBreak();
    //document.createParagraph().createRun().addBreak();

    XWPFTable productDetails = document.createTable();
    productDetails.setCellMargins(50, 50, 50, 50);
    //productDetails.getCTTbl().getTblPr().addNewJc().setVal(STJc.RIGHT);
    productDetails.getCTTbl().getTblPr().unsetTblBorders();
    productDetails.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(11000));

    XWPFTableRow pDetailHeader = productDetails.getRow(0);

    XWPFTableCell header0 = pDetailHeader.getCell(0);
    header0.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(1000));
    XWPFParagraph headerText = header0.addParagraph();
    XWPFRun run = headerText.createRun();
    run.setText("Sl. No.");
    run.setBold(true);
    ctTc = header0.getCTTc();
    tcPr = ctTc.addNewTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    XWPFTableCell header1 = pDetailHeader.createCell();
    header1.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(8000));
    XWPFParagraph headerText1 = header1.addParagraph();
    XWPFRun run1 = headerText1.createRun();
    run1.setText("Description of Goods");
    run1.setBold(true);
    ctTc = header1.getCTTc();
    tcPr = ctTc.addNewTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    XWPFTableCell header4 = pDetailHeader.createCell();
    header4.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
    XWPFParagraph headerText4 = header4.addParagraph();
    XWPFRun run4 = headerText4.createRun();
    run4.setText("Quantity");
    run4.setBold(true);
    ctTc = header4.getCTTc();
    tcPr = ctTc.addNewTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    for (int i = 0; i < 1; i++) {
        XWPFTableRow fTableRow = productDetails.createRow();
        for (int j = 0; j < 4; j++) {
            XWPFTableCell cell = fTableRow.getCell(j);
            try {
                ctTc = cell.getCTTc();
                tcPr = ctTc.addNewTcPr();
                border = tcPr.addNewTcBorders();
                //border.addNewBottom().setVal(STBorder.SINGLE);
                border.addNewRight().setVal(STBorder.SINGLE);
                border.addNewLeft().setVal(STBorder.SINGLE);
                if (i == 0)
                    border.addNewTop().setVal(STBorder.SINGLE);
            } catch (Exception e) {
                System.err.println(e.getMessage());
            }

            switch (j) {
            case 0:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(1000));
                break;
            case 1:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(8000));
                break;
            case 2:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
                break;

            }

        }
    }

    int qty = 0;

    for (int i = 0; i < table.getRowCount(); i++) {
        XWPFTableRow fTableRow = productDetails.createRow();
        for (int j = 0; j < table.getColumnCount() - 1; j++) {
            XWPFTableCell cell = fTableRow.getCell(j);
            try {
                ctTc = cell.getCTTc();
                tcPr = ctTc.addNewTcPr();
                border = tcPr.addNewTcBorders();
                if (i == table.getRowCount() - 1)
                    border.addNewBottom().setVal(STBorder.SINGLE);
                border.addNewRight().setVal(STBorder.SINGLE);
                border.addNewLeft().setVal(STBorder.SINGLE);
                //                    border.addNewTop().setVal(STBorder.SINGLE); 
            } catch (Exception e) {
                System.err.println(e.getMessage());
            }

            switch (j) {
            case 0:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(1000));
                cell.setText(String.valueOf(dtm.getValueAt(i, j)));
                break;
            case 1:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(8000));
                cell.setText(String.valueOf(dtm.getValueAt(i, j)));
                break;
            case 2:
                cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
                cell.setText(String.valueOf(dtm.getValueAt(i, j)));
                qty += Integer.parseInt(String.valueOf(dtm.getValueAt(i, j)));
                break;

            }

        }
    }

    XWPFTableRow finalRow = productDetails.createRow();
    XWPFTableCell fc0 = finalRow.getCell(0);
    fc0.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(1000));

    XWPFTableCell fc3 = finalRow.getCell(1);
    fc3.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(8000));
    XWPFParagraph fp1 = fc3.addParagraph();
    XWPFRun fRun1 = fp1.createRun();
    fRun1.setBold(true);
    fRun1.setText("TOTAL");

    XWPFTableCell fc4 = finalRow.getCell(2);
    fc4.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
    XWPFParagraph fp2 = fc4.addParagraph();
    XWPFRun fRun2 = fp2.createRun();
    fRun2.setBold(true);
    fRun2.setText(String.valueOf(qty));

    ctTc = fc0.getCTTc();
    tcPr = ctTc.getTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    //border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    ctTc = fc3.getCTTc();
    tcPr = ctTc.getTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    //border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    ctTc = fc4.getCTTc();
    tcPr = ctTc.getTcPr();
    border = tcPr.addNewTcBorders();
    border.addNewBottom().setVal(STBorder.SINGLE);
    border.addNewRight().setVal(STBorder.SINGLE);
    border.addNewLeft().setVal(STBorder.SINGLE);
    border.addNewTop().setVal(STBorder.SINGLE);

    XWPFParagraph netPMethod = document.createParagraph();
    XWPFRun pMethodRun = netPMethod.createRun();
    pMethodRun.addBreak();
    pMethodRun.addBreak();
    pMethodRun.setItalic(true);
    pMethodRun.setFontSize(10);
    pMethodRun.setText("NB. - Goods sold to the above buyer is in " + paymentType + ".");

    try {

        File f = new File(filePath);
        if (!f.exists()) {
            f.mkdir();
        }
        FileOutputStream outputStream = new FileOutputStream(filePath + File.separator + "Challan"
                + invoiceNote.replace("/", "_") + copyType.replace("/", "_") + ".docx");
        document.write(outputStream);
        outputStream.close();
        new InvoiceNoteManager().setProperty();
        if (printCommand)
            printDocument();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    return true;
}

From source file:authorslilhelper.FXMLDocumentController.java

License:Open Source License

public void createPrintable() {
    try {//from   w w w.  java  2s.  co m

        //add the LAST paragraph to paragraphs here
        /*int endOfPara = s.length() - 1;
        char cur = 'a';
        char next = 'b';
        char nextNext = 'c';
        int variableIndex = endOfPara;
                
        while(!((cur == ' ' || cur == '\n') && (next == '\n')))
        {
            cur = s.charAt(variableIndex);
            next = s.charAt(variableIndex - 1);
            //nextNext = s.charAt(variableIndex - 2);
            variableIndex--;
        }
                
        String blah = s.substring(variableIndex, endOfPara);
        paragraphs.add(blah);*/

        /*    if(current == '@')            //read in the new document and make all the chapter headers bold
            {}*/

        final Stage dialog = new Stage();
        dialog.initModality(Modality.APPLICATION_MODAL);

        final TextField textField = new TextField();
        Button submit = new Button();
        Button cancel = new Button();

        cancel.setText("Cancel");
        cancel.setAlignment(Pos.CENTER);
        submit.setText("Continue");
        submit.setAlignment(Pos.BOTTOM_RIGHT);
        // submit.

        final VBox dialogVbox = new VBox(20);
        dialogVbox.getChildren().add(new Text("What is the name/title of your book? "));
        dialogVbox.getChildren().add(textField);
        dialogVbox.getChildren().add(submit);
        dialogVbox.getChildren().add(cancel);

        Scene dialogScene = new Scene(dialogVbox, 300, 200);
        dialog.setScene(dialogScene);
        dialog.setTitle("Give your book a title ");
        dialog.show();

        submit.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent anEvent) {

                System.out.println("Hi create Printable: " + characterCapacity);

                save();

                Primary.appendText("\n\n" + "----End of Document----" + "\n");

                ArrayList paragraphs = new ArrayList();
                String s = Primary.getText();
                char current = ' ';
                char previous = ' ';
                String aParagraph = "";
                int beginningIndex = 0;

                for (int i = 0; i < s.length(); i++) {
                    current = s.charAt(i);

                    /*if(i > 0)
                    {
                        previous = s.charAt(i - 1);
                    }*/

                    if (current == '\n' && previous == '\n') {
                        aParagraph = s.substring(beginningIndex, i);

                        //todo: remove every 90th character (eg when % 90 == 0) from aParagraph before adding it
                        //THIS IS THE "IMPORTANT" BLOCK YOU BRACKETED OUT ON A WHIM
                        /*                for(int a = 0; a < aParagraph.length(); a++)
                        {   //lecturer
                            //use your "fame" to your advantage
                            //yt channel- 
                            if(a >= characterCapacity)//surprising her, as the connection grew closer/stronger and stronger, chapter titles, last paragraph getting cut off
                            {//a state of deep & profound relaxation. Sitara cared about nothing/little. It was the l itself that made the [first] entreaty, wherein she could, in idle 'conversation' beckon it/request it to mve; or to perform any operation allowed/conceivable by its physical makeup.
                                if(a % characterCapacity == 0)         //author's note: there are things in there that are pure fantasy/while the vast majority is pure fantasy, as well as things in there that are based on my real life, loosely and even closely/nearly identically, in some cases
                                {//"a polite request works better than an assertion of dominance--something you're unfamiliar with, I'm sure."
                                    StringBuilder builder = new StringBuilder(aParagraph);
                                    System.out.println(aParagraph.charAt(a));
                                    builder.deleteCharAt(a);
                                    aParagraph = builder.toString();
                                }
                            }
                        }*/

                        /*    int b = 0;
                            for(int a = 0; a < aParagraph.length(); a++)
                            {   //lecturer
                                //use your "fame" to your advantage
                                //yt channel- 
                                //if(b == characterCapacity)//surprising her, as the connection grew closer/stronger and stronger, chapter titles, last paragraph getting cut off
                                //{//a state of deep & profound relaxation. Sitara cared about nothing/little. It was the l itself that made the [first] entreaty, wherein she could, in idle 'conversation' beckon it/request it to mve; or to perform any operation allowed/conceivable by its physical makeup.
                                    //if(a % (characterCapacity) == 0)         //author's note: there are things in there that are pure fantasy/while the vast majority is pure fantasy, as well as things in there that are based on my real life, loosely and even closely/nearly identically, in some cases
                                    //{//"a polite request works better than an assertion of dominance--something you're unfamiliar with, I'm sure."
                                if(b == characterCapacity) 
                                {
                                    StringBuilder builder = new StringBuilder(aParagraph);
                                        //builder.deleteCharAt(a);
                                        //builder.deleteCharAt(a-1);
                                        System.out.println(aParagraph.charAt(a));
                                        aParagraph = builder.toString();
                                
                            b = 0;
                                    //}
                                }
                                b++;
                            }*/

                        paragraphs.add(aParagraph);

                        /*if(s.substring(i, s.length()-1).length() <= 90)
                        {
                            String finalParagraph = s.substring(i, s.length()-1);               //light-blue tiles
                            paragraphs.add(finalParagraph);
                        }*/

                        while (s.charAt(i) == ' ') {
                            i++;
                        }

                        beginningIndex = i;
                    }

                    previous = current;
                }

                String title = textField.getText();

                dialog.close();

                int result = JOptionPane.showConfirmDialog(null,
                        "In the next screen, enter a title/a unique label for your manuscript.\n If needed, this can include a version number or type.\n It does not need to have the same title as your book. \n You do NOT need to include any extensions, such as .docx--this will\n be taken care of automatically.",
                        "No extension required", JOptionPane.OK_CANCEL_OPTION); //[before returning to the login screen?]

                if (result == 0) {
                    JFileChooser chooser = new JFileChooser();
                    int value = chooser.showOpenDialog(null);
                    String saveFile = "";

                    //                            JOptionPane.showMessageDialog(null, "In the next screen, enter a title/a unique label for your manuscript. If needed, this can include a version number or type. It does not need to have the same title as your book. You do NOT need to include any extensions, such as .docx--this will be taken care of automatically.");
                    if (value == JFileChooser.APPROVE_OPTION) {
                        saveFile = chooser.getSelectedFile().getPath() + ".docx";
                    }

                    try {
                        FileOutputStream outstream = new FileOutputStream(saveFile);
                        //FileOutputStream outstream = new FileOutputStream("C:/Users/Quiggy/Desktop/Test.docx");
                        XWPFDocument doc = new XWPFDocument();

                        XWPFParagraph titlePara = doc.createParagraph();
                        titlePara.setAlignment(ParagraphAlignment.CENTER);
                        XWPFRun titleRun = titlePara.createRun();
                        titleRun.setBold(true);
                        titleRun.setFontSize(18);
                        //titleRun.setText("\n\n\n\n\n\n" + title + "\n\n\n\n\n\n\n\n");
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.addBreak();
                        titleRun.setText(title);
                        titleRun.addBreak(BreakType.PAGE);

                        XWPFParagraph contents = doc.createParagraph();
                        titlePara.setAlignment(ParagraphAlignment.CENTER);
                        XWPFRun contentsRun = contents.createRun();
                        contentsRun.setBold(true);
                        contentsRun.setFontSize(16);
                        contentsRun.setText("Contents: ");
                        contentsRun.addBreak();
                        contentsRun.addBreak();

                        XWPFParagraph chaptersNames = doc.createParagraph();
                        titlePara.setAlignment(ParagraphAlignment.CENTER);

                        int chapterCount = 0;
                        for (int c = 0; c < paragraphs.size(); c++) {
                            /*XWPFParagraph p = doc.createParagraph(); //Paragraph
                            XWPFRun run = p.createRun();  //Where the text will be written from
                            run.setText("\t");*/

                            XWPFRun chaptersRun = chaptersNames.createRun();
                            chaptersRun.setBold(false);
                            chaptersRun.setFontSize(12);
                            //chaptersRun.setText("A chapter \t\t\t\t\t\t\t\t ... ");

                            String currentParagraph = paragraphs.get(c).toString();
                            for (int d = 0; d < currentParagraph.length(); d++) {
                                if (currentParagraph.charAt(d) == '~') {
                                    chapterCount++;
                                    currentParagraph = currentParagraph.substring(d + 1,
                                            currentParagraph.length() - 2);
                                    if ((currentParagraph.indexOf("chapter") == -1)
                                            && (currentParagraph.indexOf("Chapter") == -1)
                                            && (currentParagraph.indexOf("CHAPTER") == -1)) {
                                        chaptersRun.setText("Chapter " + chapterCount + ": " + currentParagraph
                                                + "\t\t\t\t\t\t\t ... ");
                                    } else {
                                        chaptersRun.setText(currentParagraph + "\t\t\t\t\t\t\t ... ");
                                    }
                                    chaptersRun.addBreak();

                                } else {
                                    //run.setBold(false);
                                }
                            }

                            //doc.createParagraph().createRun().setText("           " + paragraphs.get(c).toString());
                            //doc.createParagraph().createRun().addBreak();
                        }

                        XWPFParagraph breakPara = doc.createParagraph();
                        titlePara.setAlignment(ParagraphAlignment.CENTER);
                        XWPFRun breakRun = breakPara.createRun();
                        breakRun.setBold(false);
                        breakRun.setFontSize(12);
                        breakRun.addBreak(BreakType.PAGE);

                        XWPFParagraph para = doc.createParagraph();
                        para.setAlignment(ParagraphAlignment.CENTER);
                        XWPFRun paraRun = para.createRun();
                        paraRun.setBold(true);
                        paraRun.setFontSize(12);//paraRun.setFontSize(16);
                        //paraRun.setText("Hello World");
                        //paraRun.setText(Primary.getText());

                        //doc.createParagraph().createRun().addBreak();                 //inserts a line break
                        //doc.createParagraph().createRun().setText("blah");            //creates another paragraph

                        for (int c = 0; c < paragraphs.size(); c++) {
                            /*XWPFParagraph p = doc.createParagraph(); //Paragraph
                            XWPFRun run = p.createRun();  //Where the text will be written from
                            run.setText("\t");*/

                            XWPFParagraph p = doc.createParagraph(); //Paragraph
                            XWPFRun run = p.createRun(); //Where the text will be written from

                            String currentParagraph = paragraphs.get(c).toString();
                            for (int d = 0; d < currentParagraph.length(); d++) {
                                if (currentParagraph.charAt(d) == '~') {
                                    currentParagraph = currentParagraph.substring(d + 1,
                                            currentParagraph.length() - 2);

                                    run.setBold(true);

                                } else {
                                    //run.setBold(false);
                                }
                            }

                            run.setText("           " + currentParagraph);
                            run.addBreak(); //NEW!

                            //doc.createParagraph().createRun().setText("           " + paragraphs.get(c).toString());
                            //doc.createParagraph().createRun().addBreak();
                        }

                        doc.write(outstream);
                        outstream.close();
                    } catch (Exception io) {
                    }
                    //JOptionPane.showConfirmDialog(null, "Are you sure you want to create the word document?");

                    //Makes the chapter titles bold and removes the "@" & "-"

                    JOptionPane.showMessageDialog(null,
                            "Document Successfully Created. The program/AA will now exit");
                    try {
                        if (Desktop.isDesktopSupported()) {
                            Desktop.getDesktop().open(new File(saveFile));
                        }
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                    System.exit(0);
                }
                if (result == 1) {

                }
                /*if(result == 2)
                {
                        
                }*/

            }
        });

        cancel.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent anEvent) {
                dialog.close();
                //close the window here
            }
        });

    } catch (Exception e) {

    }
}

From source file:biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.java

License:Apache License

public static void setDocCellValue(XWPFTable dxTable, int nRow, int nCol, Object objValue, int maxRow,
        boolean isHeader) {

    try {//from   www .  j  a  v  a  2 s . co m
        if (dxTable.getRow(nRow) == null) {
            // DEFINIE MAX VALUE!
            while (dxTable.getRow(nRow) == null && dxTable.getRows().size() < maxRow) {
                dxTable.createRow();
                // rowHasChanged = true;
            }
        }
        if (dxTable.getRow(nRow) != null) {
            if (dxTable.getRow(nRow).getCell(nCol) == null) {
                // CHECK MAX COL
                while (dxTable.getRow(nRow).getCell(nCol) == null
                        && dxTable.getRow(nRow).getTableCells().size() < 50) {
                    dxTable.getRow(nRow).addNewTableCell();
                }
            }

            // dxTable.getRow(nRow).getCell(nCol).setText("" +
            // objValue.toString());

            for (XWPFParagraph paraCurrent : dxTable.getRow(nRow).getCell(nCol).getParagraphs()) {
                if (paraCurrent.getRuns().size() == 0) {
                    XWPFRun runCurrent = paraCurrent.createRun();
                    if (isHeader)
                        runCurrent.setBold(true);
                    runCurrent.setText("" + objValue.toString());
                } else {
                    for (XWPFRun runCurrent : paraCurrent.getRuns()) {
                        if (isHeader)
                            runCurrent.setBold(true);
                        runCurrent.setText("" + objValue.toString());
                    }
                }
            }

        } else {
            System.out.println("Still null: " + nRow + " MaxRow = " + maxRow);
        }

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

From source file:br.com.techne.gluonsoft.eowexport.builder.WordBuilder.java

License:Apache License

/**
 * adiciona titulo/*from  w  w w . ja  v  a2s . co m*/
 * @param rows
 * @param titles
 */
private static void addTitle(List<XWPFTableRow> rows, String[] titles) {
    //adicionando titulo
    XWPFTableRow row = rows.get(0);
    // get table row properties (trPr)
    CTTrPr trPr = row.getCtRow().addNewTrPr();
    // set row height; units = twentieth of a point, 360 = 0.25"
    CTHeight ht = trPr.addNewTrHeight();
    ht.setVal(BigInteger.valueOf(360));
    // get the cells in this row
    List<XWPFTableCell> cells = row.getTableCells();
    int colCt = 0;

    //CTTblWidth tblWidth = CTTblWidth.Factory.newInstance();
    //tblWidth.setW(BigInteger.valueOf(200));
    //tblWidth.setType(STTblWidth.DXA);

    // add content to each cell
    for (XWPFTableCell cell : cells) {
        // get a table cell properties element (tcPr)
        CTTcPr tcpr = cell.getCTTc().addNewTcPr();
        //tcpr.setTcW(tblWidth);

        // set vertical alignment to "center"
        CTVerticalJc va = tcpr.addNewVAlign();
        va.setVal(STVerticalJc.CENTER);

        // create cell color element
        CTShd ctshd = tcpr.addNewShd();
        ctshd.setColor("auto");
        ctshd.setVal(STShd.CLEAR);
        // header row
        ctshd.setFill("A7BFDE");
        // get 1st paragraph in cell's paragraph list
        XWPFParagraph para = cell.getParagraphs().get(0);
        // create a run to contain the content
        XWPFRun rh = para.createRun();

        // header row
        if ((titles.length - 1) < colCt) {
            rh.setText("");
        } else
            rh.setText(titles[colCt]);

        rh.setBold(true);
        para.setAlignment(ParagraphAlignment.CENTER);

        colCt++;
    } // for cell
}

From source file:certificatecreator.CertificateCreator.java

private void createStudentCertificate(String tempPath) {
    //Creates student certificate.
    //Read in template file and define output file.
    File inFile = new File(tempPath);
    File outFile = new File(userPath + File.separator + selectedStudent + "Certificate.docx");
    //Create output file. Throw alert if tempPath references nonexisting file.
    try {//w ww.  java2s  .  c o m
        copy(inFile, outFile);
        //Create internal word document based on copied template file. Write content.
        try {
            XWPFDocument certificate = new XWPFDocument(new FileInputStream(outFile));
            XWPFParagraph p1 = certificate.createParagraph();
            p1.setAlignment(ParagraphAlignment.CENTER);
            XWPFRun r1 = p1.createRun();
            r1.setFontFamily("Candara");
            r1.setFontSize(40);
            r1.addBreak();
            r1.setText("Lawton Elementary Congratulates");
            XWPFRun r2 = p1.createRun();
            r2.setFontFamily("Candara");
            r2.setFontSize(36);
            r2.setBold(true);
            r2.addBreak();
            r2.addBreak();
            r2.setText(selectedStudent);
            r2.addBreak();
            r2.addBreak();
            XWPFRun r3 = p1.createRun();
            r3.setFontFamily("Candara");
            r3.setFontSize(26);
            r3.setText("For being a Lawton CARES winner on");
            r3.addBreak();
            String date = getDate();
            r3.setText(date);
            r3.addBreak();
            r3.addBreak();
            r3.addBreak();
            r3.addBreak();
            XWPFRun r4 = p1.createRun();
            r4.setColor("5B9BD5");
            r4.setFontFamily("Candara");
            r4.setFontSize(26);
            r4.setText("Compassion+Attitude+Respect+Effort+Safety=CARES");
            //Write internal document to copied templated file.
            try {
                FileOutputStream out = new FileOutputStream(outFile.toString());
                try {
                    certificate.write(out);
                    out.close();
                } catch (IOException io) {
                    System.err.println("Could not write file: " + io);
                }
            } catch (FileNotFoundException fnf) {
                System.err.println("Could not find output file: " + fnf);
            }
        } catch (IOException io) {
            System.err.println("Copy of template could not be found: " + io);
        }
    } catch (IOException io) {
        System.err.println("Method copy failed:" + io);
    } catch (NullPointerException npe) {
        System.err.println("Method copy failed:" + npe);
        Alert templateNotFound = new Alert(AlertType.WARNING,
                "Specified certificate template was not found. " + "Please choose a different template.");
        templateNotFound.showAndWait();
    }
}

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);/*from  w w  w  .  j a  v a 2  s .  com*/
    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:cn.wantedonline.porobot.DataBaseEntity.java

License:Apache License

private static void genDBDictionary(List<DBTableBean> tableBeans) throws IOException {
    XWPFDocument doc = new XWPFDocument();
    String databaseName = "default_database";
    for (DBTableBean bean : tableBeans) {
        databaseName = bean.getDatabaseName();
        XWPFParagraph p0 = doc.createParagraph();
        p0.setAlignment(ParagraphAlignment.CENTER);
        XWPFRun r0 = p0.createRun();
        r0.setBold(true);
        r0.setText(databaseName);/*from w  ww . j ava 2 s .  c om*/
        r0.setFontSize(16);
        XWPFParagraph p1 = doc.createParagraph();
        p1.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun r1 = p1.createRun();
        r1.setBold(true);
        r1.setText("Table:" + bean.getTableName());
        XWPFTable table = doc.createTable();
        int pos = 0;
        XWPFTableRow row1 = table.insertNewTableRow(pos++);
        XWPFTableCell cell1 = row1.createCell();
        cell1.setText("Field");
        cell1.setColor("FFE4C4");
        XWPFTableCell cell2 = row1.createCell();
        cell2.setText("Type");
        cell2.setColor("FFE4C4");
        XWPFTableCell cell3 = row1.createCell();
        cell3.setText("Comment");
        cell3.setColor("FFE4C4");
        for (int i = 0; i < bean.getColumnSize(); i++) {
            XWPFTableRow row = table.insertNewTableRow(pos++);
            XWPFTableCell cell11 = row.createCell();
            cell11.setText(bean.getColumnName(i));
            XWPFTableCell cell22 = row.createCell();
            cell22.setText(bean.getColumnType(i));
            XWPFTableCell cell33 = row.createCell();
            cell33.setText(bean.getColumnComment(i));
        }
        table.removeRow(pos);
        XWPFParagraph p2 = doc.createParagraph();
        XWPFRun r2 = p2.createRun();
        r2.addBreak();
    }

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

}

From source file:com.Base.JavaApplication1.java

public static void save(String path) {

    try {/*from w  ww  . j a va  2s.c o m*/

        // JOptionPane.showMessageDialog(null, "Start ImageDoc","Error",JOptionPane.INFORMATION_MESSAGE);
        //String comment=comment;
        XWPFDocument docx = new XWPFDocument();

        //  JOptionPane.showMessageDialog(null, "create ImageDoc","Error",JOptionPane.INFORMATION_MESSAGE);

        XWPFParagraph par = docx.createParagraph();
        XWPFRun run = par.createRun();
        run.setText(comment);
        run.setFontSize(13);

        FileOutputStream out = new FileOutputStream(path);

        //JOptionPane.showMessageDialog(null, "Dir"+dir+"\\"+name,"Error",JOptionPane.INFORMATION_MESSAGE);
        // byte [] picbytes = IOUtils.toByteArray(pic);

        // run.setText("Software Genrated File");

        File f = new File("C:\\images\\*.*");
        String str = f.getParent();
        File k = new File(str);
        String list[] = k.list();

        JOptionPane.showMessageDialog(null, "Reading Files", "Error", JOptionPane.INFORMATION_MESSAGE);
        for (int y = 0; y < list.length; y++) {
            InputStream pic = new FileInputStream("C:\\images\\" + list[y]);
            XWPFRun run2 = par.createRun();
            // run2.setText("Screen Shot No."+(y+1));

            run2.addPicture(pic, Document.PICTURE_TYPE_JPEG, "C:\\images\\" + list[y], Units.toEMU(500),
                    Units.toEMU(350));
            // XWPFRun run2 = title.createRun();
            run2.setText("ScreenShot :" + (y + 1));
            pic.close();
            System.gc();
        }

        //run.setText("Hello, World. This is my first java generated docx-file. Have fun2shhhh.");

        // FileInputStream pic2 = new FileInputStream("D:\\i.png");
        //byte [] picbytes2 = IOUtils.toByteArray(pic);
        //docx.addPictureData(IOUtils.toByteArray(pic2), Document.PICTURE_TYPE_PNG);

        //  docx.createParagraph().createRun().addPicture(pic, Document.PICTURE_TYPE_JPEG, "D:\\images\\image0.jpg", Units.toEMU(500), Units.toEMU(500));

        XWPFParagraph title = docx.createParagraph();
        XWPFRun run2 = title.createRun();
        run2.setText(" ");
        run2.setBold(true);
        title.setAlignment(ParagraphAlignment.CENTER);

        JOptionPane.showMessageDialog(null, "Writing File", "Error", JOptionPane.INFORMATION_MESSAGE);

        System.out.println(dir + name);

        docx.write(out);

        out.close();
        //  pic.close();
        JOptionPane.showMessageDialog(null, "Operation Complete", "Error", JOptionPane.INFORMATION_MESSAGE);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "No Image to save!" + e, "Error", JOptionPane.ERROR_MESSAGE);
    }

}

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

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

    //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;
}