Example usage for org.apache.poi.xwpf.usermodel ParagraphAlignment LEFT

List of usage examples for org.apache.poi.xwpf.usermodel ParagraphAlignment LEFT

Introduction

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

Prototype

ParagraphAlignment LEFT

To view the source code for org.apache.poi.xwpf.usermodel ParagraphAlignment LEFT.

Click Source Link

Usage

From source file:org.cgiar.ccafs.marlo.action.summaries.POWBPOISummaryAction.java

License:Open Source License

private void createTableH() {
    List<List<POIField>> headers = new ArrayList<>();
    POIField[] sHeader = {//from w w  w.java 2s  .com
            new POIField(
                    this.getText("monitoringLearning.table.plannedStudies",
                            new String[] { String.valueOf(this.getSelectedYear()) }),
                    ParagraphAlignment.CENTER),
            new POIField(this.getText("monitoringLearning.table.comments"), ParagraphAlignment.CENTER) };
    List<POIField> header = Arrays.asList(sHeader);
    headers.add(header);

    List<List<POIField>> datas = new ArrayList<>();
    List<POIField> data;

    this.getFpPlannedList(this.getFlagships(), this.getSelectedPhase().getId());
    for (PowbEvidencePlannedStudyDTO powbEvidencePlannedStudyDTO : flagshipPlannedList.stream().filter(p -> p
            .getProjectExpectedStudy() != null
            && p.getProjectExpectedStudy().getType() != null
            && (p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.EVAULATION.getId()
                    || p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.IMPACTASSESMENT.getId()
                    || p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.LEARNING.getId()
                    || p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.IMPACTCASESTUDY.getId()
                    || p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.CRP_PTF.getId()
                    || p.getProjectExpectedStudy().getType() == TypeExpectedStudiesEnum.REVIEW.getId()))
            .collect(Collectors.toList())) {
        String plannedStudy = "", comments = "";
        plannedStudy = powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getTopicStudy() != null
                && !powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getTopicStudy().trim().isEmpty()
                        ? powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getTopicStudy()
                        : " ";
        comments = powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getComments() != null
                && !powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getComments().trim().isEmpty()
                        ? powbEvidencePlannedStudyDTO.getProjectExpectedStudy().getComments()
                        : " ";

        POIField[] sData = { new POIField(plannedStudy, ParagraphAlignment.LEFT),
                new POIField(comments, ParagraphAlignment.LEFT) };

        data = Arrays.asList(sData);
        datas.add(data);
    }

    poiSummary.textTable(document, headers, datas, false, "tableH");
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

/**
 * Footer title/* w  w  w  .  ja v  a 2 s  . c  o m*/
 * 
 * @param document
 * @param text
 * @throws IOException
 */
public void pageFooter(XWPFDocument document, String text) throws IOException {
    CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
    XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(document, sectPr);
    CTP ctpFooter = CTP.Factory.newInstance();
    CTR ctrFooter = ctpFooter.addNewR();
    CTText ctFooter = ctrFooter.addNewT();
    ctFooter.setStringValue(text);
    XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, document);
    footerParagraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFParagraph[] parsFooter = new XWPFParagraph[1];
    parsFooter[0] = footerParagraph;
    policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);
}

From source file:Sluzhebka.Creating_doc.java

/** 
*  ? ? ?     docx/*w  ww. j av  a2s .c om*/
* JOptionPane ?? ? ?? .
*/
public void generate_document() {
    try {
        wave_to_saving_docx = wave_to_saving_docx + "\\? ?.docx";
        FileOutputStream outStream = new FileOutputStream(wave_to_saving_docx);
        XWPFDocument doc = new XWPFDocument();
        ArrayList<XWPFParagraph> docPar = new ArrayList<XWPFParagraph>();
        ArrayList<String> treats = new ArrayList<String>();
        ArrayList<String> centr = new ArrayList<String>();
        treats = formate_treatment();
        centr = formate_centrText();
        for (int i = 0; i < treats.size(); i++) {
            docPar.add(doc.createParagraph());
            docPar.get(i).setIndentationLeft(5000);
            docPar.get(i).setAlignment(ParagraphAlignment.LEFT);
            XWPFRun docRun = docPar.get(i).createRun();
            docRun.setFontFamily("Times New Roman");
            docRun.setFontSize(14);
            docRun.setText(treats.get(i));
        }
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.CENTER);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.CENTER);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.CENTER);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.CENTER);
        XWPFRun docRun = docPar.get(docPar.size() - 1).createRun();
        docRun.setFontFamily("Times New Roman");
        docRun.setFontSize(16);
        docRun.setText("?? ??");
        for (int i = 0; i < centr.size(); i++) {
            docPar.add(doc.createParagraph());
            docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);
            XWPFRun docRun1 = docPar.get(docPar.size() - 1).createRun();
            docRun1.setFontFamily("Times New Roman");
            docRun1.setFontSize(14);
            docRun1.setText(centr.get(i));
        }
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);

        Date currentDate = new Date();
        Locale local = new Locale("ru", "RU");
        DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, local);
        currentDate = new Date();
        String last_str = treats.get(treats.size() - 1)
                + "                                                                   "
                + df.format(currentDate);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);
        docPar.add(doc.createParagraph());
        docPar.get(docPar.size() - 1).setAlignment(ParagraphAlignment.LEFT);
        XWPFRun docRun1 = docPar.get(docPar.size() - 1).createRun();
        docRun1.setFontFamily("Times New Roman");
        docRun1.setFontSize(14);
        docRun1.setText(last_str);
        doc.write(outStream);
        outStream.close();
        JOptionPane.showMessageDialog(null, "? ?");

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:smsapp.utils.WriteSMSToDocFile.java

public void setDocument() {
    try {//w  ww.j  a v  a  2 s  .c om
        os = new FileOutputStream("_gendocs/" + generateDocName());
        doc = new XWPFDocument();
        para = doc.createParagraph();
        para.setAlignment(ParagraphAlignment.LEFT);
        paraRun = para.createRun();
        paraRun.setBold(false);
        paraRun.setFontSize(12);

        System.out.println("Doc name: \t" + ModelSmsApp.getDocName());

    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
    }
}

From source file:smsapp.utils.WriteSMSToDocFile.java

public void setDocument(String docName) {
    try {//from   www  .  ja v  a 2s .  c  om
        os = new FileOutputStream("_gendocs/" + docName);
        doc = new XWPFDocument();
        para = doc.createParagraph();
        para.setAlignment(ParagraphAlignment.LEFT);
        paraRun = para.createRun();
        paraRun.setBold(false);
        paraRun.setFontSize(12);

    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
    }
}

From source file:UserInterface.SalesSpecialistWorkArea.SalesSpecialistWorkAreaJPanel.java

private void generateInvoice(SalesSpecialistWorkRequest salesRequest) {

    double invoiceAmount = 0;
    order = salesRequest.getOrder();/*from www. ja v  a2 s.  c o 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: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);/*w ww. j  a v  a  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();

}

From source file:Utils.FileHandler.java

private void fullWidthPicture(XWPFDocument doc, File imgFile) throws InvalidFormatException, IOException {
    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun imageRun = p2.createRun();//  w  ww.  j av  a  2 s .c  om
    imageRun.setTextPosition(10);
    imageRun.setText("        ");
    imageRun.setFontSize(1);
    imageRun.addPicture(new FileInputStream(imgFile), XWPFDocument.PICTURE_TYPE_PNG, "image", Units.toEMU(469),
            Units.toEMU(274));
    p2.setBorderBottom(Borders.SINGLE);
    p2.setBorderTop(Borders.SINGLE);
    p2.setBorderRight(Borders.SINGLE);
    p2.setBorderLeft(Borders.SINGLE);

}