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

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

Introduction

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

Prototype

public void addBreak() 

Source Link

Document

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

Usage

From source file:sofmeth.mco3.gui.TPTFrame.java

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
    // TODO add your handling code here:
    XWPFDocument document = new XWPFDocument();
    try {/*from   ww  w.j  a  va  2s . c  o  m*/
        FileOutputStream out = new FileOutputStream(new File("task planning template.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Defect Recording Log");
        run.setBold(true);
        run.setFontSize(16);
        //end making of title
        //adding name etc to document
        XWPFTable details = document.createTable(2, 2);
        //setting cell width
        CTTblWidth width = details.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));
        //end setting cell width
        //computation

        for (int i = 0; i < 10; i++) {

            if (tptTable.getModel().getValueAt(i, 3) != null
                    && !tptTable.getModel().getValueAt(i, 3).toString().isEmpty()) {

                pValue = pValue + Float.parseFloat(tptTable.getModel().getValueAt(i, 3).toString());
            }
            if (tptTable.getModel().getValueAt(i, 2) != null
                    && !tptTable.getModel().getValueAt(i, 2).toString().isEmpty()) {

                tHours = tHours + Float.parseFloat(tptTable.getModel().getValueAt(i, 2).toString());
            }

        }

        //
        //details.getCTTbl().getTblPr().unsetTblBorders();
        XWPFTableRow dtlRow = details.getRow(0);
        dtlRow.getCell(0).setText("Name: " + nameField);
        dtlRow.getCell(1).setText("Date: " + dateField);
        dtlRow = details.getRow(1);
        dtlRow.getCell(0).setText("Professor: " + profField);
        dtlRow.getCell(1).setText("Program#: " + progNumField);
        //end adding name to document
        para = document.createParagraph();
        run = para.createRun();
        run.addBreak();
        run.addBreak();

        //creating of TPT table
        XWPFTable table = document.createTable(5, 10);

        width = table.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));
        /*
                
        TODO: make all loops like this while loops?
        */
        for (int i = -1; i < 10; i++) {

            if (i == 9)
                break;
            if (i == -1) { //top row of the table
                XWPFTableRow row1 = table.getRow(i + 1);
                for (int j = 0; j < 10; j++) {

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Number");
                        break;
                    case 1:
                        row1.getCell(j).setText("Name");
                        break;
                    case 2:
                        row1.getCell(j).setText("Hours");
                        break;
                    case 3:
                        row1.getCell(j).setText("Planned Value");
                        break;
                    case 4:
                        row1.getCell(j).setText("Cumulative Hours");
                        break;
                    case 5:
                        row1.getCell(j).setText("Cumulative Planned Values");
                        break;
                    case 6:
                        row1.getCell(j).setText("Date(Plan)");
                        break;
                    case 7:
                        row1.getCell(j).setText("Date(Actual)");
                        break;
                    case 8:
                        row1.getCell(j).setText("Earned Value");
                        break;
                    case 9:
                        row1.getCell(j).setText("Cumulative Value");
                        break;

                    }

                }
            }
            //although this code assumes that there are values inside
            //UPDATE1: ok i fixed it i think
            else {
                XWPFTableRow row = table.getRow(i + 1);
                for (int j = 0; j < 10; j++) {
                    if (tptTable.getModel().getValueAt(i, 1) != null
                            && !tptTable.getModel().getValueAt(i, j).toString().isEmpty()) {

                        if (tptTable.getModel().getValueAt(i, j) != null
                                && !tptTable.getModel().getValueAt(i, j).toString().isEmpty())

                            row.getCell(j).setText(tptTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }
        }
        table = document.createTable(2, 1);
        XWPFTableRow row = table.getRow(0);
        row.getCell(0).setText("Total Hours: " + tHours);
        row = table.getRow(1);
        row.getCell(0).setText("Total Planned Value: " + pValue);
        document.write(out);
        out.close();
    } catch (Exception e) {

    }
}

From source file:sofmeth.mco3.gui.TRLFrame.java

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
    // TODO add your handling code here:

    XWPFDocument document = new XWPFDocument();
    try {/* w w w .j a  va  2s  .c  o m*/
        FileOutputStream out = new FileOutputStream(new File("time recording log.docx"));
        //start of title making
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Time Recording Log");
        run.setBold(true);
        run.setFontSize(16);
        //end title making
        XWPFTable details = document.createTable(3, 2);
        //setting cell width
        CTTblWidth width = details.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));
        //end setting cell width
        //details.getCTTbl().getTblPr().unsetTblBorders();
        XWPFTableRow dtlRow = details.getRow(0);
        dtlRow.getCell(0).setText("Name: " + nameField);
        dtlRow.getCell(1).setText("Date: " + dateField);
        dtlRow = details.getRow(1);
        dtlRow.getCell(0).setText("Program: " + progField);
        dtlRow.getCell(1).setText("Program#: " + progNumField);
        dtlRow = details.getRow(2);
        dtlRow.getCell(0).setText("Professor: " + profField);
        dtlRow.getCell(1).setText("Language: " + langField);
        //end adding name to document
        para = document.createParagraph();
        run = para.createRun();
        run.addBreak();
        run.addBreak();

        XWPFTable table = document.createTable(6, 7);
        width = table.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));
        for (int i = -1; i < 6; i++) {

            if (i == 5)
                break;
            if (i == -1) { //top row of the table
                XWPFTableRow row1 = table.getRow(i + 1);
                for (int j = 0; j < 7; j++) {

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Date");
                        break;
                    case 1:
                        row1.getCell(j).setText("Start");
                        break;
                    case 2:
                        row1.getCell(j).setText("Stop");
                        break;
                    case 3:
                        row1.getCell(j).setText("Interruption Time");
                        break;
                    case 4:
                        row1.getCell(j).setText("Delta Time");
                        break;
                    case 5:
                        row1.getCell(j).setText("Phase");
                        break;
                    case 6:
                        row1.getCell(j).setText("Comments");
                        break;

                    }

                }
            }
            //although this code assumes that there are values inside
            //UPDATE1: ok i fixed it i think
            else {
                XWPFTableRow row = table.getRow(i + 1);
                for (int j = 0; j < 7; j++) {

                    if (trlTable.getModel().getValueAt(i, j) != null
                            && !trlTable.getModel().getValueAt(i, j).toString().isEmpty())
                        row.getCell(j).setText(trlTable.getModel().getValueAt(i, j).toString());

                }
            }

        }
        document.write(out);

        out.close();

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

From source file:sofmeth.mco3.gui.TRTFrame.java

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
    // TODO add your handling code here:
    XWPFDocument document = new XWPFDocument();
    try {/*from w  ww . ja  v  a 2  s .c o  m*/
        FileOutputStream out = new FileOutputStream(new File("test report template.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Test Report Template");
        run.setBold(true);
        run.setFontSize(16);
        //end making of title
        //start making name table
        XWPFTable details = document.createTable(2, 2);
        //setting cell width
        CTTblWidth width = details.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9000));
        //end setting cell width
        //details.getCTTbl().getTblPr().unsetTblBorders();
        XWPFTableRow row = details.getRow(0);
        row.getCell(0).setText("Name: " + nameField);
        row.getCell(1).setText("Date: " + nameField);
        row = details.getRow(1);
        row.getCell(0).setText("Professor: " + profField);
        row.getCell(1).setText("Program#: " + progNumField);

        para = document.createParagraph();
        run = para.createRun();
        run.addBreak();
        run.addBreak();
        //end making name table
        while (true) {
            if (trtTable.getModel().getValueAt(i, 0) != null
                    && !trtTable.getModel().getValueAt(i, 0).toString().isEmpty()) {
                XWPFTable table = document.createTable(6, 2);
                width = table.getCTTbl().addNewTblPr().addNewTblW();
                width.setType(STTblWidth.DXA);
                width.setW(BigInteger.valueOf(9500));

                for (int j = 0; j < 6; j++) {
                    row = table.getRow(j);
                    switch (j) {
                    case 0:
                        row.getCell(0).setText("Test Number");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 0).toString());
                        break;
                    case 1:
                        row.getCell(0).setText("Test Objective");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 1).toString());
                        break;
                    case 2:
                        row.getCell(0).setText("Test Description");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 2).toString());
                        break;
                    case 3:
                        row.getCell(0).setText("Test Conditions");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 3).toString());
                        break;
                    case 4:
                        row.getCell(0).setText("Expected Results");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 4).toString());
                        break;
                    case 5:
                        row.getCell(0).setText("Actual Results");
                        row.getCell(1).setText(trtTable.getModel().getValueAt(i, 5).toString());
                        break;
                    }
                }
                para = document.createParagraph();
                run = para.createRun();
                run.addBreak();
                run.addBreak();
                i++;
            } else
                break;
        }
        document.write(out);
        out.close();
    } catch (Exception e) {

    }
}

From source file:UserInterface.SalesSpecialistWorkArea.SalesSpecialistWorkAreaJPanel.java

private void generateInvoice(SalesSpecialistWorkRequest salesRequest) {

    double invoiceAmount = 0;
    order = salesRequest.getOrder();//from ww w . j  a v  a  2s .  co m
    XWPFDocument document = new XWPFDocument();

    XWPFParagraph paragraph1 = document.createParagraph();
    XWPFRun run1 = paragraph1.createRun();

    run1.setText("Invoice Report");
    run1.setBold(true);
    run1.setUnderline(UnderlinePatterns.DOUBLE);
    run1.setFontSize(30);
    paragraph1.setAlignment(ParagraphAlignment.CENTER);

    for (OrderItem orderItem : salesRequest.getOrder().getOrderItem()) {
        invoiceAmount = invoiceAmount + (orderItem.getQuantity() * orderItem.getDevice().getUnitPrice());
    }

    XWPFParagraph paragraph3 = document.createParagraph();
    XWPFRun run3 = paragraph3.createRun();

    run3.setText("Invoice Amount : " + invoiceAmount);
    run3.setBold(true);
    run3.setUnderline(UnderlinePatterns.DOUBLE);
    run3.setFontSize(30);
    paragraph3.setAlignment(ParagraphAlignment.LEFT);

    XWPFParagraph paragraph2 = document.createParagraph();
    XWPFRun run2 = paragraph2.createRun();
    int count = 0;
    for (OrderItem orderItem : order.getOrderItem()) {
        run2.addBreak();
        run2.addBreak();
        count++;
        run2.setText("OrderItem " + count);
        run2.addBreak();
        Device device = orderItem.getDevice();
        run2.setText("Device Name : " + device.getDeviceName());
        run2.addBreak();
        run2.setText("Device Type : " + device.getDeviceType());
        run2.addBreak();
        run2.setText("Company Name : " + device.getCompanyName());
        run2.addBreak();
        run2.setText("Unit Price : " + device.getUnitPrice());
        run2.addBreak();
        run2.setText("Country of Origin : " + device.getCountryOfOrigin());
        run2.addBreak();
        run2.setText("Manufactured Date : " + device.getManufacuredDate());
        run2.addBreak();
        run2.setText("Quantity : " + orderItem.getQuantity());
        run2.addBreak();
        run2.setText("The unique identifiers for " + orderItem.getQuantity() + " device are listed below");
        run2.addBreak();
        for (String uID : orderItem.getuIDList()) {
            run2.setText(uID);
            run2.addBreak();
        }
    }
    run2.setFontSize(30);
    paragraph2.setAlignment(ParagraphAlignment.LEFT);

    try {

        //Next 3 lines are to create a word file
        FileOutputStream output = new FileOutputStream("Invoice_Report.docx");
        document.write(output);

        //XWPFWordExtractor extract = new XWPFWordExtractor(document);
        output.close();

        Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler "
                + "C:\\Users\\Tushar\\Google Drive\\NetBeansProjects\\Word\\Invoice_Report.docx");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:UtilsPackage.MakeRapport.java

private void createRapport(ObservableList<ModelNice> oNices) {
    if (document == null)
        return;//www. ja  va  2  s . c o m

    int numPage = 1;
    for (ModelNice model : oNices) {
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();

        run.setFontSize(18);

        run.setText("Page: " + numPage);
        run.addBreak();
        run.addBreak();
        run.setText("Event Id: " + model.getEventId().toString());
        run.addBreak();
        run.setText("Event Type: " + model.getEventType());
        run.addBreak();
        run.setText("Categorie: " + model.getCategorie());
        run.addBreak();
        run.setText("Numro appelant: " + model.getNumCaller());
        run.addBreak();
        run.setText("Numro appel: " + model.getNumCalled());
        run.addBreak();
        run.addBreak();
        run.setText("Synopsis:");
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();

        run.setFontSize(14);
        run.setText(model.getSynopsis());
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();

        run.setFontSize(18);
        run.setText("Content:");
        run.addBreak();

        paragraph = document.createParagraph();
        run = paragraph.createRun();

        run.setFontSize(14);
        run.setText(model.getSmsContent());
        run.addBreak(BreakType.PAGE);

        // page +1
        numPage++;
    }

}