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

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

Introduction

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

Prototype

public void setUnderline(UnderlinePatterns value) 

Source Link

Document

Specifies that the contents of this run should be displayed along with an underline appearing directly below the character height.

Usage

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) {// w  w  w .j a  v a 2 s  . com
    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);
    }
}

From source file:ro.dabuno.office.integration.SimpleDocument.java

License:Apache License

public static void main(String[] args) throws Exception {
    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p0 = doc.createParagraph();
    XWPFRun r0 = p0.createRun();/* www.ja  v a 2 s  . co  m*/
    r0.setBold(false);
    r0.setText("Domnule");
    XWPFRun r00 = p0.createRun();
    r00.setBold(true);
    r00.setText(" Ionescu Ion");

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);
    p1.setBorderTop(Borders.DOUBLE);

    p1.setBorderRight(Borders.DOUBLE);
    p1.setBorderLeft(Borders.DOUBLE);
    p1.setBorderBetween(Borders.SINGLE);

    p1.setVerticalAlignment(TextAlignment.TOP);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setBold(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    XWPFParagraph p2 = doc.createParagraph();
    p2.setAlignment(ParagraphAlignment.RIGHT);

    //BORDERS
    p2.setBorderBottom(Borders.DOUBLE);
    p2.setBorderTop(Borders.DOUBLE);
    p2.setBorderRight(Borders.DOUBLE);
    p2.setBorderLeft(Borders.DOUBLE);
    p2.setBorderBetween(Borders.SINGLE);

    XWPFRun r2 = p2.createRun();
    r2.setText("jumped over the lazy dog");
    r2.setStrike(true);
    r2.setFontSize(20);

    XWPFRun r3 = p2.createRun();
    r3.setText("and went away");
    r3.setStrike(true);
    r3.setFontSize(20);
    r3.setSubscript(VerticalAlign.SUPERSCRIPT);

    XWPFParagraph p3 = doc.createParagraph();
    p3.setWordWrap(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    p3.setSpacingLineRule(LineSpacingRule.EXACT);

    p3.setIndentationFirstLine(600);

    XWPFRun r4 = p3.createRun();
    r4.setTextPosition(20);
    r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer "
            + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, "
            + "And by opposing end them? To die: to sleep; ");
    r4.addBreak(BreakType.PAGE);
    r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks "
            + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; "
            + "To sleep: perchance to dream: ay, there's the rub; " + ".......");
    r4.setItalic(true);
    //This would imply that this break shall be treated as a simple line break, and break the line after that word:

    XWPFRun r5 = p3.createRun();
    r5.setTextPosition(-10);
    r5.setText("For in that sleep of death what dreams may come");
    r5.addCarriageReturn();
    r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect"
            + "That makes calamity of so long life;");
    r5.addBreak();
    r5.setText("For who would bear the whips and scorns of time,"
            + "The oppressor's wrong, the proud man's contumely,");

    r5.addBreak(BreakClear.ALL);
    r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns"
            + ".......");

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

}

From source file:UserInterface.SalesSpecialistWorkArea.SalesSpecialistWorkAreaJPanel.java

private void generateInvoice(SalesSpecialistWorkRequest salesRequest) {

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

private void boldText(XWPFParagraph paragraph, String text, boolean underline) {
    XWPFRun r = paragraph.createRun();
    r.setText(text);//from w  w  w  .  jav  a 2 s.c om
    r.setBold(true);

    if (underline) {
        r.setUnderline(UnderlinePatterns.SINGLE);
    }
}