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

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

Introduction

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

Prototype

public void addTab() 

Source Link

Document

Specifies that a tab shall be placed at the current location in the run content.

Usage

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   ww w .  j  a  v a 2s .c o m
    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:com.crimelab.service.GalleryServiceImpl.java

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

    //Insert into database
    galleryDAO.insertResults(galleryResults);

    try {
        //Retrieving Template
        InputStream inpDocx = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/CompositeSketch.docx");
        document = new XWPFDocument(inpDocx);

        //Adding the picture
        XWPFParagraph pictureHolder = document.createParagraph();
        XWPFRun pictureRun = pictureHolder.createRun();

        FileInputStream getPhoto = new FileInputStream(galleryResults.getPhotoLocation());
        FileInputStream getImage = new FileInputStream(galleryResults.getPhotoLocation());
        ImageInputStream imageInput = ImageIO.createImageInputStream(getPhoto);
        BufferedImage bi = ImageIO.read(imageInput);
        int width = bi.getWidth() - 100;
        int height = bi.getHeight() - 100;

        pictureRun.addBreak();
        pictureRun.addPicture(getImage, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(width),
                Units.toEMU(height));

        pictureHolder.setBorderBottom(Borders.BASIC_BLACK_DASHES);
        pictureHolder.setBorderTop(Borders.BASIC_BLACK_DASHES);
        pictureHolder.setBorderLeft(Borders.BASIC_BLACK_DASHES);
        pictureHolder.setBorderRight(Borders.BASIC_BLACK_DASHES);
        pictureHolder.setAlignment(ParagraphAlignment.CENTER);
        //            pictureRowHolder.getCell(0).setText("IMAGE PLACER");

        //Case number and Date            
        XWPFParagraph info = document.createParagraph();
        XWPFRun caseNoAndDate = info.createRun();
        caseNoAndDate.setText("Case Number: " + galleryResults.getCaseNo());
        caseNoAndDate.addTab();
        caseNoAndDate.addTab();
        caseNoAndDate.addTab();
        caseNoAndDate.addTab();
        caseNoAndDate.setText(galleryResults.getDate());
        caseNoAndDate.setFontSize(16);

        //Sketch Details
        XWPFParagraph caseDetails = document.createParagraph();
        XWPFRun detailsParagraph = caseDetails.createRun();
        detailsParagraph.setText("Offense/Incident: " + galleryResults.getOffenseIncident());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Name/AKA: " + galleryResults.getNameAKA());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Sex: " + galleryResults.getSex());
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.setText("Age: " + galleryResults.getAge());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Height: " + galleryResults.getHeight());
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.setText("Weight: " + galleryResults.getWeight());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Built: " + galleryResults.getBuilt());
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.addTab();
        detailsParagraph.setText("Complexion: " + galleryResults.getComplexion());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Other Information: " + galleryResults.getOtherInfo());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Described by: " + galleryResults.getDescribedBy());
        detailsParagraph.addBreak();
        detailsParagraph.setText("Requesting party: " + galleryResults.getRequestingParty());

        //Details Borders
        caseDetails.setBorderBottom(Borders.BASIC_BLACK_DASHES);
        caseDetails.setBorderTop(Borders.BASIC_BLACK_DASHES);
        caseDetails.setBorderLeft(Borders.BASIC_BLACK_DASHES);
        caseDetails.setBorderRight(Borders.BASIC_BLACK_DASHES);
        caseDetails.setAlignment(ParagraphAlignment.LEFT);

        //Reference Paragraph
        XWPFParagraph outsideDetails = document.createParagraph();
        XWPFRun outsideDetailsRun = outsideDetails.createRun();
        outsideDetailsRun.addBreak();
        outsideDetailsRun.setText("Note: For reference");
        outsideDetailsRun.addBreak();
        outsideDetailsRun.setText("The witness indicates that this image is: " + galleryResults.getRating());
        getPhoto.close();
        getImage.close();
        imageInput.close();
        document.getXWPFDocument();
    } catch (IOException | InvalidFormatException e) {
        e.printStackTrace();
    }
    return document;
}

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  2 s.  c  om*/

    //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:MainPackage.Controllers.BookController.java

private XWPFRun createRun(XWPFParagraph paragraph, String text) {
    XWPFRun run;
    run = paragraph.createRun();//  w ww  . jav a2s .c  o  m
    run.setText(text);
    run.addTab();
    return run;
}

From source file:MainPackage.Controllers.BookController.java

private XWPFParagraph createBookProductInformation(XWPFDocument document, BookViewModel bookView) {
    XWPFParagraph paragraph = document.createParagraph();

    paragraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun run = createFieldRun(paragraph, "Thng tin Sn phm: ");
    run.setFontSize(16);/*w w w .  j ava 2 s . c  o m*/
    run.addCarriageReturn();

    ArrayList<PrintRunField> productInformations = new ArrayList<PrintRunField>() {
        {
            add(new PrintRunField("M sch: ", bookView.IdCode));
            add(new PrintRunField("M ISBN: ", bookView.ISBN));
            add(new PrintRunField("Ti khon to: ", bookView.CreatedBy));
            add(new PrintRunField("Th?i gian to: ", bookView.CreateTime));
            add(new PrintRunField("Gi sch: ", bookView.Price));
            add(new PrintRunField("Tnh trng: ", bookView.Status));
        }
    };

    for (int i = 0; i < productInformations.size(); i++) {

        run = createFieldRun(paragraph, productInformations.get(i).Field);
        run.addTab();
        run = createValueRun(paragraph, productInformations.get(i).Value);
        if (i % 2 == 0) {
            run.addTab();
        } else {
            run.addCarriageReturn();
        }
    }

    return paragraph;
}

From source file:MainPackage.Controllers.BookController.java

private XWPFParagraph createBookInformation(XWPFDocument document, BookViewModel bookView) {
    XWPFParagraph paragraph = document.createParagraph();

    XWPFRun run = createFieldRun(paragraph, "Thng tin Sch: ");
    run.setFontSize(16);//from  w ww. j a  v  a  2 s. c  o m
    run.addCarriageReturn();

    ArrayList<PrintRunField> bookInformations = new ArrayList<PrintRunField>() {
        {
            add(new PrintRunField("Tn sch: ", bookView.Name));
            add(new PrintRunField("Tc gi: ", bookView.Author));
            add(new PrintRunField("Nh xut bn: ", bookView.Publisher));
            add(new PrintRunField("Th loi: ", bookView.Type));
            add(new PrintRunField("Pht hnh: ", bookView.PublishMonth + "/" + bookView.PublishYear));
            add(new PrintRunField("M t:      ", bookView.Details));
        }
    };

    for (PrintRunField bookInformation : bookInformations) {
        run = createFieldRun(paragraph, bookInformation.Field);
        run.addTab();
        run = createValueRun(paragraph, bookInformation.Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:MainPackage.Controllers.OrderController.java

private XWPFParagraph createBookProductInformation(XWPFDocument document, Orders order) {
    XWPFParagraph paragraph = document.createParagraph();

    paragraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun run = createFieldRun(paragraph, "Thng tin Ha n: ");
    run.setFontSize(16);/*from   ww w  .  j  av a2 s.co m*/
    run.addCarriageReturn();

    ArrayList<BookController.PrintRunField> productInformations = new ArrayList<BookController.PrintRunField>() {
        {
            add(new BookController.PrintRunField("M Ha n: ", order.getIdCode()));
            add(new BookController.PrintRunField("Ti khon lp: ", order.getCreateBy().getUsername()));
            add(new BookController.PrintRunField("Th?i gian lp: ",
                    getDateTimeString(order.getCreateTime())));
            add(new BookController.PrintRunField(" ", ""));
            add(new BookController.PrintRunField("Tng ti?n: ", IntToVND(order.getTotalPrice())));
            add(new BookController.PrintRunField("Thu VAT: ", IntToVND(order.getVATPrice())));
            add(new BookController.PrintRunField("Khuyn mi: ", IntToVND(order.getDiscount())));
            add(new BookController.PrintRunField("Thanh ton: ", IntToVND(order.getPaidPrice())));
        }
    };

    for (int i = 0; i < productInformations.size(); i++) {

        run = createFieldRun(paragraph, productInformations.get(i).Field);
        run.addTab();
        run = createValueRun(paragraph, productInformations.get(i).Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:MainPackage.Controllers.OrderController.java

private XWPFParagraph createBookInformation(XWPFDocument document, Orders order) {
    XWPFParagraph paragraph = document.createParagraph();

    XWPFRun run = createFieldRun(paragraph, "Thng tin Khch hng: ");
    run.setFontSize(16);/*from   w ww.  j a va2  s .  c o  m*/
    run.addCarriageReturn();

    ArrayList<BookController.PrintRunField> bookInformations = new ArrayList<BookController.PrintRunField>() {
        {
            add(new BookController.PrintRunField("Tn khch: ", order.getGuestName()));
            add(new BookController.PrintRunField("?a ch: ", order.getGuestPhone()));
            add(new BookController.PrintRunField("?in thoi: ", order.getGuestPhone()));
            add(new BookController.PrintRunField("Email:      ", order.getGuestEmail()));
            add(new BookController.PrintRunField(" ", ""));
            add(new BookController.PrintRunField("Ghi ch: ", order.getDetails()));
        }
    };

    for (BookController.PrintRunField bookInformation : bookInformations) {
        run = createFieldRun(paragraph, bookInformation.Field);
        run.addTab();
        run = createValueRun(paragraph, bookInformation.Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java

License:Open Source License

/**
 * Insert the given text into to given {@link XWPFRun}. This take care of new lines and tabulations.
 * //w w  w .j  a v a 2  s  .  c  o m
 * @param srcRun
 *            the {@link XWPFRun} to populate
 * @param text
 *            the text
 * @return the last inserted {@link XWPFRun}.
 */
private XWPFRun insertString(XWPFRun srcRun, String text) {
    int fragmentStart = 0;

    XWPFRun inserted;
    for (int i = 0; i < text.length(); i++) {
        final char current = text.charAt(i);
        switch (current) {
        case '\n':
            inserted = insertFragment(srcRun, text.substring(fragmentStart, i));
            inserted.addBreak();
            fragmentStart = i + 1;
            break;
        case '\t':
            inserted = insertFragment(srcRun, text.substring(fragmentStart, i));
            inserted.addTab();
            fragmentStart = i + 1;
            break;
        case '\r':
            // CHECKSTYLE:OFF
            if (i + 1 < text.length() && text.charAt(i + 1) == '\n') {
                inserted = insertFragment(srcRun, text.substring(fragmentStart, i));
                inserted.addBreak();
                i++;
                fragmentStart = i + 1;
            }
            // CHECKSTYLE:ON
            break;

        default:
            break;
        }
    }

    return insertFragment(srcRun, text.substring(fragmentStart, text.length()));
}

From source file:pe.gob.onpe.rae.controller.registro.registroController.java

@RequestMapping(value = "generateFVDoc/{codExpediente}", method = RequestMethod.GET)
public void generateFVDoc(HttpServletRequest request, @PathVariable("codExpediente") int codExpediente,
        HttpServletResponse response) {//from w w w  .j  av  a  2 s .  c  o  m
    try {
        ServletContext sc = request.getSession().getServletContext();

        Expediente expediente = new Expediente(codExpediente);
        expediente = expedienteDAO.find(expediente);

        Ambito amb = new Ambito(expediente.getAmbito().getId());
        amb = ambitoDAO.find(amb);

        int totalElectoresRemitidos = expedientePadronDAO.getCountByExpediente(expediente);
        int totalElectoresIncorporados = expedientePadronDAO.getCountByExpedienteAndEstado(expediente,
                Parametros.ESTADO_ELECTOR_ACTIVO);

        JsonParser jsonParser = new JsonParser();
        JsonObject jsonObject = (JsonObject) jsonParser.parse(amb.getInformacion());
        String nombre = jsonObject.get("nombres").toString() + " "
                + jsonObject.get("apellidoPaterno").toString() + " "
                + jsonObject.get("apellidoMaterno").toString();

        InputStream is = registroController.class.getResourceAsStream("/ejemplo.docx");
        XWPFDocument document = new XWPFDocument(is);

        XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy();
        if (policy == null) {
            CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
            policy = new XWPFHeaderFooterPolicy(document, sectPr);
        }

        if (policy.getDefaultHeader() == null && policy.getFirstPageHeader() == null
                && policy.getDefaultFooter() == null) {
            XWPFFooter footerD = policy.getFooter(1);// createFooter(policy.DEFAULT);
            XWPFRun run = footerD.getParagraphs().get(0).createRun();
            run.setText("usuario");
            XWPFParagraph paragraph = footerD.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.DISTRIBUTE);
            run = paragraph.createRun();
            run.setFontFamily("Arial");
            run.setFontSize(8);
            run.setText(
                    "Jr.Washington N 1894, Cercado de Lima. Central Telefonica: 417-0630 www.onpe.gob.pe informes@onpe.gob.pe");

        }

        XWPFParagraph paragraph = document.createParagraph();

        XWPFRun run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setText("Lima,");
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setBold(true);
        run.setText("OFICIO N       -2016-GPP/ONPE");
        run.setUnderline(UnderlinePatterns.SINGLE);
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setText("Seor");

        XWPFRun run1 = paragraph.createRun();
        run1.setFontSize(11);
        run1.setFontFamily("Arial");
        run1.setText(nombre.replace("\"", ""));
        run1.setBold(true);
        run1.addBreak();

        XWPFRun run2 = paragraph.createRun();
        run2.setFontSize(11);
        run2.setFontFamily("Arial");
        run2.setText(jsonObject.get("cargo").toString().replace("\"", ""));
        run2.addBreak();
        run2.setText("Centro Poblado " + amb.getNombreAmbito());
        run2.addBreak();
        run2.setText("Av. 28 de Julio S/N Centro Cvico Huacrachuco - Municipalidad Provincial de "
                + amb.getProvincia());
        run2.addBreak();
        run2.setText(amb.getDepartamento() + " - " + amb.getProvincia() + " - " + amb.getDistrito());
        run2.addBreak();

        run2 = paragraph.createRun();
        run2.setFontSize(11);
        run2.setFontFamily("Arial");
        run2.setUnderline(UnderlinePatterns.WORDS);
        run2.setText("Presente");

        run2 = paragraph.createRun();
        run2.setFontSize(11);
        run2.setFontFamily("Arial");
        run2.setText(".-");

        paragraph = document.createParagraph();
        run.addBreak();
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.setText("Asunto");
        run.addTab();
        run.addTab();
        run.setText(": SOLICITUD DE CREACIN DE MESA DE SUFRAGIO.");
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setText("Referencia");
        run.addTab();
        run.setText(": OFICIO N 087-2016/M-CP.CHOCOBAMBA (16AGO2016) - Exp. " + expediente.getExpediente());
        run.addBreak();

        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setText(
                "Me dirijo a usted con relacin al documento de la referencia con la finalidad de hacer de su "
                        + "conocimiento que se ha cumplido con todos los requisitos que dan inicio al trmite de "
                        + "instalacin de mesas de sufragio en el Centro Poblado " + amb.getNombreAmbito()
                        + ", distrito " + amb.getDistrito() + ", " + "provincia " + amb.getProvincia()
                        + ", departamento " + amb.getDepartamento() + ".");
        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.setText("Al respecto, el mencionado expediente contiene un listado de electores que solicitan ser "
                + "parte de la mesa de sufragio de la localidad " + amb.getNombreAmbito()
                + ", el cual, luego de la validacin " + "realizada, se informa que podrn ser incorporados "
                + totalElectoresIncorporados + " electores del total de " + totalElectoresRemitidos
                + " registros "
                + "de electores remitidos. Se adjunta un cuadro resumen con las observaciones mencionadas.");
        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.setText(
                "Asimismo, se programar un viaje para la verificacin de rutas, tiempos y servicios de la "
                        + "localidad, la cual se coordinar previamente con las autoridades del centro poblado a fin de "
                        + "programarla adecuadamente; luego de lo cual se emitir un informe de respuesta al "
                        + "resultado de la solicitud, que de ser positivo, conllevara a la instalacin de mesas de sufragio "
                        + "en el centro poblado en mencin, con miras a las ");
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.setBold(true);
        run.setText("Elecciones Regionales y Municipales de 2018.");
        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.setText("Finalmente, de requerir mayor informacin, agradeceremos se comunique con nosotros al "
                + "telefono 417-0630 anexo 8484 o al 8481.");
        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.setText("Sin otro particular.");

        paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
        run = paragraph.createRun();
        run.setFontSize(11);
        run.setFontFamily("Arial");
        run.addBreak();
        run.addBreak();
        run.setText("Atentamente,");
        response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
        document.write(response.getOutputStream());
    } catch (Exception ex) {
        Logger.getLogger(registroController.class.getName()).log(Level.SEVERE, null, ex);
    }
}