Example usage for org.apache.poi.xwpf.usermodel XWPFParagraph setAlignment

List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph setAlignment

Introduction

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

Prototype

public void setAlignment(ParagraphAlignment align) 

Source Link

Document

Specifies the paragraph alignment which shall be applied to text in this paragraph.

Usage

From source file:sofmeth.mco3.gui.Result2AFrame.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 w w  . ja  v a  2 s . co m
        FileOutputStream out = new FileOutputStream(new File("program 2a results.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Program 2A Results");
        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
        //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(11, 2);

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

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

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Program Number");
                        break;
                    case 1:
                        row1.getCell(j).setText("LOC");
                        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 < 2; j++) {
                    if (resultTable.getModel().getValueAt(i, 1) != null
                            && !resultTable.getModel().getValueAt(i, j).toString().isEmpty()) {

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

                            row.getCell(j).setText(resultTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }
        }
        document.write(out);
        out.close();
    } catch (Exception e) {

    }
}

From source file:sofmeth.mco3.gui.Result3AFrame.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 . ja  va 2s . c o  m*/
        FileOutputStream out = new FileOutputStream(new File("program 3a results.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Program 3A Results");
        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
        //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(11, 4);

        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 < 11; i++) {

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

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Program Number");
                        break;
                    case 1:
                        row1.getCell(j).setText("Function Name");
                        break;
                    case 2:
                        row1.getCell(j).setText("Object LOC");
                        break;
                    case 3:
                        row1.getCell(j).setText("Total LOC");

                    }

                }
            }
            //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 < 4; j++) {
                    if (resultTable.getModel().getValueAt(i, 1) != null
                            && !resultTable.getModel().getValueAt(i, j).toString().isEmpty()) {

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

                            row.getCell(j).setText(resultTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }
        }
        document.write(out);
        out.close();
    } catch (Exception e) {

    }
}

From source file:sofmeth.mco3.gui.SETFrame.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  ww.  j a v  a2 s . c o m*/
        FileOutputStream out = new FileOutputStream(new File("size estimating template.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Size Estimating Template");
        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
        //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();

        //computation
        for (int i = 0; i < 6; i++) {

            if (locTable.getModel().getValueAt(i, 4) != null
                    && !locTable.getModel().getValueAt(i, 4).toString().isEmpty()) {

                bSize = bSize + Integer.parseInt(locTable.getModel().getValueAt(i, 4).toString());
            }

        }
        for (int i = 0; i < 6; i++) {

            if (noTable.getModel().getValueAt(i, 4) != null
                    && !noTable.getModel().getValueAt(i, 4).toString().isEmpty()) {

                totalNew = totalNew + Integer.parseInt(noTable.getModel().getValueAt(i, 4).toString());
            }

        }
        for (int i = 0; i < 6; i++) {

            if (roTable.getModel().getValueAt(i, 1) != null
                    && !roTable.getModel().getValueAt(i, 1).toString().isEmpty()) {

                reTotal = reTotal + Integer.parseInt(roTable.getModel().getValueAt(i, 1).toString());
            }

        }

        pLoc = bSize + totalNew;
        int b0 = Integer.parseInt(b0Field.getText());
        int b1 = Integer.parseInt(b1Field.getText());
        esNew = b0 + b1 * (pLoc + locMod);
        esTotal = esNew + bSize - locDeleted - locMod + reTotal;
        //

        //creating of TPT table
        XWPFTable table = document.createTable(1, 1);
        width = table.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));

        XWPFTableRow row = table.getRow(0);
        row.getCell(0).setText("Base Program");

        table = document.createTable(3, 2);

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

            row = table.getRow(i);
            switch (i) {
            case 0:
                row.getCell(0).setText("Base Size(B)");
                row.getCell(1).setText(baseField.getText());
                break;
            case 1:
                row.getCell(0).setText("LOC Deleted(D)");
                row.getCell(1).setText(delField.getText());
                break;
            case 2:
                row.getCell(0).setText("LOC Modified(M)");
                row.getCell(1).setText(modField.getText());
                break;
            }
        }

        para = document.createParagraph();
        run = para.createRun();
        table = document.createTable(1, 1);
        width = table.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));
        row = table.getRow(0);
        row.getCell(0).setText("Projected LOC (P)");

        table = document.createTable(7, 5);

        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 < 5; j++) {

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Base Additions");
                        break;
                    case 1:
                        row1.getCell(j).setText("Type");
                        break;
                    case 2:
                        row1.getCell(j).setText("Methods");
                        break;
                    case 3:
                        row1.getCell(j).setText("Relative Size");
                        break;
                    case 4:
                        row1.getCell(j).setText("LOC");
                        break;

                    }

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

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

                            row.getCell(j).setText(locTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }

        }

        System.out.print(bSize);

        table = document.createTable(1, 2);
        row = table.getRow(0);
        row.getCell(0).setText("Total Base Additions(BA)");
        row.getCell(1).setText(Integer.toString(bSize));

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

        table = document.createTable(7, 5);
        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 < 5; j++) {

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("New Objects(NO)");
                        break;
                    case 1:
                        row1.getCell(j).setText("Type");
                        break;
                    case 2:
                        row1.getCell(j).setText("Methods");
                        break;
                    case 3:
                        row1.getCell(j).setText("Relative Size");
                        break;
                    case 4:
                        row1.getCell(j).setText("LOC");
                        break;

                    }

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

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

                            row.getCell(j).setText(noTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }

        }
        table = document.createTable(1, 2);
        row = table.getRow(0);
        row.getCell(0).setText("Total New Objects(NO)");
        row.getCell(1).setText(Integer.toString(totalNew));

        para = document.createParagraph();
        //para.setPageBreak(true);

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

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

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Reused Objects");
                        break;
                    case 1:
                        row1.getCell(j).setText("LOC");
                        break;

                    }

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

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

                            row.getCell(j).setText(roTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }

        }
        table = document.createTable(1, 2);
        row = table.getRow(0);
        row.getCell(0).setText("Reused Total(R)");
        row.getCell(1).setText(Integer.toString(reTotal));

        para = document.createParagraph();
        table = document.createTable(5, 2);
        width = table.getCTTbl().addNewTblPr().addNewTblW();
        width.setType(STTblWidth.DXA);
        width.setW(BigInteger.valueOf(9500));

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

            row = table.getRow(i);
            switch (i) {
            case 0:
                row.getCell(0).setText("Projected LOC(P)");
                row.getCell(1).setText(Integer.toString(pLoc));
                break;
            case 1:
                row.getCell(0).setText("Regression Parameter(B0)");
                row.getCell(1).setText(Integer.toString(b0));
                break;
            case 2:
                row.getCell(0).setText("Regression Parameter(B1)");
                row.getCell(1).setText(Integer.toString(b1));
                break;
            case 3:
                row.getCell(0).setText("Estimated New and Changed LOC(N)");
                row.getCell(1).setText(Integer.toString(esNew));
                break;
            case 4:
                row.getCell(0).setText("Estimated Total LOC(T)");
                row.getCell(1).setText(Integer.toString(esTotal));
                break;
            }
        }

        document.write(out);
        out.close();

    } catch (Exception e) {

    }

}

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

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
    // TODO add your handling code here:
    XWPFDocument document = new XWPFDocument();
    //write document
    try {/*from www  .j a  va 2 s .  c om*/
        FileOutputStream out = new FileOutputStream(new File("sourcecode.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Source Code Listing");
        run.setBold(true);
        run.setFontSize(16);
        //end making of title
        para = document.createParagraph();
        run = para.createRun();

        //adding name etc to document
        XWPFTable details = document.createTable(3, 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: " + dateField);
        row = details.getRow(1);
        row.getCell(0).setText("Program: " + progField);
        row.getCell(1).setText("Program#: " + progNumField);
        row = details.getRow(2);
        row.getCell(0).setText("Professor: " + profField);
        row.getCell(1).setText("Language: " + langField);
        //end adding name to document

        para = document.createParagraph();
        run = para.createRun();
        run.addBreak();
        run.addBreak();
        String sourceCode = codeTextArea.getText();
        if (sourceCode.contains("\n")) {
            String[] lines = sourceCode.split("\n");
            run.setText(lines[0], 0);
            for (int i = 1; i < lines.length; i++) {

                run.addBreak();
                if (lines[i].contains("\t")) {
                    int tabSpace = lines[i].length() - lines[i].replaceAll("\t", "").length();
                    for (int j = 0; j < tabSpace; j++) {
                        run.addTab();
                    }
                }
                run.setText(lines[i]);
            }
        } else
            run.setText(sourceCode);

        //sourceCode.replaceAll("\\n", "&#xA;");
        document.write(out);
        out.close();

    } catch (Exception e) {

    }

}

From source file:sofmeth.mco3.gui.SPTFrame.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  w w.ja va2  s .  c o m
        FileOutputStream out = new FileOutputStream(new File("schedule planning template.docx"));
        //making of title
        XWPFParagraph para = document.createParagraph();
        para.setAlignment(ParagraphAlignment.CENTER);
        para.setSpacingAfter(500);
        XWPFRun run = para.createRun();
        run.setText("Schedule Planning Template");
        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
        //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(12, 9);
        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 < 9; j++) {

                    switch (j) { //no formatting yet like bold etc
                    case 0:
                        row1.getCell(j).setText("Week/Day Number");
                        break;
                    case 1:
                        row1.getCell(j).setText("Date");
                        break;
                    case 2:
                        row1.getCell(j).setText("Direct Hours");
                        break;
                    case 3:
                        row1.getCell(j).setText("Cumulative");
                        break;
                    case 4:
                        row1.getCell(j).setText("Cumulative Value");
                        break;
                    case 5:
                        row1.getCell(j).setText("Direct Hours");
                        break;
                    case 6:
                        row1.getCell(j).setText("Cumulative Hours");
                        break;
                    case 7:
                        row1.getCell(j).setText("Cumulative Value");
                        break;
                    case 8:
                        row1.getCell(j).setText("Adjusted 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 < 9; j++) {
                    if (sptTable.getModel().getValueAt(i, 1) != null
                            && !sptTable.getModel().getValueAt(i, j).toString().isEmpty()) {

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

                            row.getCell(j).setText(sptTable.getModel().getValueAt(i, j).toString());
                    } else
                        break;
                }
            }
        }
        document.write(out);
        out.close();
    } catch (Exception e) {

    }
}

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 www.  j  a va 2  s . com*/
        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 {/*from   w  w  w  .  j a v a  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 w w.ja v a 2 s.  co  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();/*  w  w w . j a  v  a  2s. c  om*/
    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:Utils.FileHandler.java

public void createReport(String designerName, String projectName, File crossSectionImg, File img1, File img2,
        File img3, Model model, DSMCalcs dsm)
        throws FileNotFoundException, IOException, InvalidFormatException {

    //Start of document
    XWPFDocument doc = new XWPFDocument();

    XWPFTable poiTable = doc.createTable(1, 3);

    //Paragraph 1
    XWPFParagraph p1 = poiTable.getRow(0).getCell(0).getParagraphs().get(0);
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setVerticalAlignment(TextAlignment.CENTER);
    p1.setSpacingAfter(0);//from   w w  w  .  j  a  va 2 s.  c o m

    boldText(p1, "Designer: ");
    text(p1, designerName);

    //Project
    XWPFParagraph p8 = poiTable.getRow(0).getCell(1).getParagraphs().get(0);
    p8.setAlignment(ParagraphAlignment.CENTER);
    p8.setVerticalAlignment(TextAlignment.CENTER);
    p8.setSpacingAfter(0);
    boldText(p8, "Project: ");
    text(p8, projectName);

    XWPFParagraph p9 = poiTable.getRow(0).getCell(2).getParagraphs().get(0);
    p9.setAlignment(ParagraphAlignment.CENTER);
    p9.setVerticalAlignment(TextAlignment.CENTER);
    p9.setSpacingAfter(0);

    boldText(p9, "Date: ");

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();

    text(p9, dateFormat.format(date));

    CTTbl table = poiTable.getCTTbl();
    CTTblPr pr = table.getTblPr();
    CTTblWidth tblW = pr.getTblW();
    tblW.setW(BigInteger.valueOf(5000));
    tblW.setType(STTblWidth.PCT);
    pr.setTblW(tblW);
    table.setTblPr(pr);

    XWPFParagraph modelParagraph = doc.createParagraph();
    modelParagraph.setAlignment(ParagraphAlignment.LEFT);
    lineBreak(modelParagraph);
    boldText(modelParagraph, "Model Properties:", true);
    lineBreak(modelParagraph);
    boldText(modelParagraph, "File Path: ");
    text(modelParagraph, "C:\\Users\\SJ\\Documents\\NetBeansProjects\\Stripper");
    lineBreak(modelParagraph);
    boldText(modelParagraph, "Maximum allowable stress: ");
    text(modelParagraph, Double.toString(model.getAllowableStress()));
    lineBreak(modelParagraph);
    boldText(modelParagraph, "Cross-sectional Area: ");
    text(modelParagraph, Double.toString(model.getCrossSectionalArea()));
    lineBreak(modelParagraph);

    boldText(modelParagraph, "Ixx: ");
    text(modelParagraph, Double.toString(model.getIxx()));
    lineBreak(modelParagraph);

    boldText(modelParagraph, "Ixx (principal): ");
    text(modelParagraph, Double.toString(model.getIxxPrincipal()));
    lineBreak(modelParagraph);

    boldText(modelParagraph, "Izz: ");
    text(modelParagraph, Double.toString(model.getIzz()));
    lineBreak(modelParagraph);

    boldText(modelParagraph, "Izz (principal): ");
    text(modelParagraph, Double.toString(model.getIzzPrincipal()));

    XWPFParagraph materialParagraph = doc.createParagraph();
    materialParagraph.setAlignment(ParagraphAlignment.LEFT);
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Material Properties: ", true);
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Material name: ");
    text(materialParagraph, model.getModelMaterial().getName());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Young's Modulus (Ex): ");
    text(materialParagraph, "" + model.getModelMaterial().getEx());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Young's Modulus (Ey): ");
    text(materialParagraph, "" + model.getModelMaterial().getEy());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Poisson Ratio (vx): ");
    text(materialParagraph, "" + model.getModelMaterial().getVx());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Poisson Ratio (vy): ");
    text(materialParagraph, "" + model.getModelMaterial().getVy());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Shear Modulus (G): ");
    text(materialParagraph, "" + model.getModelMaterial().getG());
    lineBreak(materialParagraph);
    boldText(materialParagraph, "Yield Stress: ");
    text(materialParagraph, "" + model.getModelMaterial().getFy());
    lineBreak(materialParagraph);

    if (crossSectionImg != null) {
        boldText(doc.createParagraph(), "Cross-Section: ", true);
        fullWidthPicture(doc, crossSectionImg);
    }
    pageBreak(doc.createParagraph());

    if (img1 != null) {
        XWPFParagraph p = doc.createParagraph();
        boldText(p, "Local Buckling Factor chosen by user: ", true);
        p.setSpacingAfter(0);
        lineBreak(p);
        fullWidthPicture(doc, img1);
    }

    if (img2 != null) {
        XWPFParagraph p = doc.createParagraph();
        boldText(p, "Distortional Buckling Factor chosen by user: ", true);
        p.setSpacingAfter(0);
        lineBreak(p);
        fullWidthPicture(doc, img2);
    }

    if (img3 != null) {
        XWPFParagraph p = doc.createParagraph();
        boldText(p, "Global Buckling Factor chosen by user: ", true);
        p.setSpacingAfter(0);
        lineBreak(p);
        fullWidthPicture(doc, img3);
    }
    pageBreak(doc.createParagraph());

    String type = "None";
    String local = "";
    String distortional = "";
    String global = "";
    String yield = "";
    double l = 0;
    double d = 0;
    double g = 0;
    double y = 0;

    if (dsm.getAnalysisType() == DSMCalcs.analysisType.BEAM) {
        type = "Beam";
        local = "Mcrl";
        distortional = "Mcrd";
        global = "Mcrd";
        yield = "My";
        l = dsm.getMcrl();
        d = dsm.getMcrd();
        g = dsm.getMcre();
        y = dsm.getMy();

    }
    if (dsm.getAnalysisType() == DSMCalcs.analysisType.COLUMN) {
        type = "Column";
        local = "Pcrl";
        distortional = "Pcrd";
        global = "Pcre";
        yield = "Py";
        l = dsm.getPcrl();
        d = dsm.getPcrd();
        g = dsm.getPcre();
        y = dsm.getPy();
    }

    XWPFParagraph inputParagraph = doc.createParagraph();
    boldText(inputParagraph, "DSM Input: ", true);
    lineBreak(inputParagraph);
    text(inputParagraph, "Analysis type: " + type);
    lineBreak(inputParagraph);
    text(inputParagraph, yield + " = " + y);
    lineBreak(inputParagraph);
    text(inputParagraph, local + " = " + l);
    lineBreak(inputParagraph);
    text(inputParagraph, distortional + " = " + d);
    lineBreak(inputParagraph);
    text(inputParagraph, global + " = " + g);

    String[] calcs = dsm.getTextArea().getText().split("\n");
    XWPFParagraph calcParagraph = doc.createParagraph();
    boldText(calcParagraph, "DSM Calculations: ", true);
    lineBreak(calcParagraph);
    for (int i = 0; i < calcs.length; i++) {
        text(calcParagraph, calcs[i]);
        lineBreak(calcParagraph);
    }

    fileDialog.getExtensionFilters().add(new ExtensionFilter("MS Word", "*.docx"));
    File file = fileDialog.showSaveDialog(null);

    FileOutputStream out = new FileOutputStream(file);
    doc.write(out);
    out.close();
    fileDialog.getExtensionFilters().clear();

}