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

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

Introduction

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

Prototype

@Override
public void setFontSize(int size) 

Source Link

Document

Specifies the font size which shall be applied to all non complex script characters in the contents of this run when displayed.

Usage

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

License:Open Source License

/**
 * Apply the given style to the given run. Background color is not taken into account here since it does not apply to runs.
 * /*from   w w  w.j  av  a  2  s.  com*/
 * @param run
 *            The run to style
 * @param style
 *            The style to apply, can be <code>null</code>
 */
private void applyTableClientStyle(XWPFRun run, MStyle style) {
    run.setFontSize(style.getFontSize());
    run.setBold((style.getFontModifiers() & MStyle.FONT_BOLD) != 0);
    run.setItalic((style.getFontModifiers() & MStyle.FONT_ITALIC) != 0);
    if ((style.getFontModifiers() & MStyle.FONT_UNDERLINE) != 0) {
        run.setUnderline(UnderlinePatterns.SINGLE);
    }
    run.setStrikeThrough((style.getFontModifiers() & MStyle.FONT_STRIKE_THROUGH) != 0);
    run.setColor(hexColor(style.getForegroundColor()));
}

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

License:Open Source License

/**
 * Inserts the given {@link TemplateValidationMessage} in a run next to the one of the given construct subject to the message.
 * /*ww  w  .j  ava 2s.  co m*/
 * @param message
 *            the {@link TemplateValidationMessage} to insert
 *            the error message to insert in a run
 * @param offset
 *            the offset in number of {@link XWPFRun} to insert after {@link TemplateValidationMessage#getLocation() message location}
 * @return the number of inserted {@link XWPFRun}
 */
private int addRunError(TemplateValidationMessage message, int offset) {
    int res = 0;

    if (message.getLocation().getParent() instanceof XWPFParagraph) {
        XWPFParagraph paragraph = (XWPFParagraph) message.getLocation().getParent();
        final int basePosition = paragraph.getRuns().indexOf(message.getLocation()) + offset;

        // separation run.
        res++;
        final String color = M2DocUtils.getColor(message.getLevel());
        XWPFRun newBlankRun = paragraph.insertNewRun(basePosition + res);
        newBlankRun.setText(BLANK_SEPARATOR);

        res++;
        final XWPFRun separationRun = paragraph.insertNewRun(basePosition + res);
        separationRun.setText(LOCATION_SEPARATOR);
        separationRun.setColor(color);
        separationRun.setFontSize(ERROR_MESSAGE_FONT_SIZE);
        final CTHighlight separationHighlight = separationRun.getCTR().getRPr().addNewHighlight();
        separationHighlight.setVal(STHighlightColor.LIGHT_GRAY);

        res++;
        final XWPFRun messageRun = paragraph.insertNewRun(basePosition + res);
        messageRun.setText(message.getMessage());
        messageRun.setColor(color);
        messageRun.setFontSize(ERROR_MESSAGE_FONT_SIZE);
        final CTHighlight messageHighlight = messageRun.getCTR().getRPr().addNewHighlight();
        messageHighlight.setVal(STHighlightColor.LIGHT_GRAY);
    }

    return res;
}

From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java

License:Apache License

private static void addSourceTablesAppendix(CustomXWPFDocument document, ETL etl) {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.addBreak(BreakType.PAGE);//from  ww  w .j  a va  2 s .  c o m
    run.setText("Appendix: source tables");
    run.setFontSize(18);

    for (Table sourceTable : etl.getSourceDatabase().getTables()) {
        paragraph = document.createParagraph();
        run = paragraph.createRun();
        run.setText("Table: " + sourceTable.getName());
        run.setFontSize(14);

        createDocumentParagraph(document, sourceTable.getComment());

        XWPFTable table = document.createTable(sourceTable.getFields().size() + 1, 4);
        // table.setWidth(2000);
        XWPFTableRow header = table.getRow(0);
        setTextAndHeaderShading(header.getCell(0), "Field");
        setTextAndHeaderShading(header.getCell(1), "Type");
        setTextAndHeaderShading(header.getCell(2), "Most freq. value");
        setTextAndHeaderShading(header.getCell(3), "Comment");
        int rowNr = 1;
        for (Field sourceField : sourceTable.getFields()) {
            XWPFTableRow row = table.getRow(rowNr++);
            row.getCell(0).setText(sourceField.getName());
            row.getCell(1).setText(sourceField.getType().toString());
            if (sourceField.getValueCounts() != null && sourceField.getValueCounts().length != 0)
                row.getCell(2).setText(sourceField.getValueCounts()[0][0]);
            createCellParagraph(row.getCell(3), sourceField.getComment().trim());
        }

    }

    run.setFontSize(18);
}

From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java

License:Apache License

private static void addTargetTableSection(CustomXWPFDocument document, ETL etl, Table targetTable)
        throws InvalidFormatException, FileNotFoundException {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.addBreak(BreakType.PAGE);//ww w.  j a va2  s  . c  om

    run.setText("Table name: " + targetTable.getName());
    run.setFontSize(18);

    createDocumentParagraph(document, targetTable.getComment());

    for (ItemToItemMap tableToTableMap : etl.getTableToTableMapping().getSourceToTargetMaps())
        if (tableToTableMap.getTargetItem() == targetTable) {
            Table sourceTable = (Table) tableToTableMap.getSourceItem();
            Mapping<Field> fieldtoFieldMapping = etl.getFieldToFieldMapping(sourceTable, targetTable);

            paragraph = document.createParagraph();
            run = paragraph.createRun();
            run.setText("Reading from " + tableToTableMap.getSourceItem());
            run.setFontSize(14);

            createDocumentParagraph(document, tableToTableMap.getLogic());

            createDocumentParagraph(document, tableToTableMap.getComment());

            // Add picture of field to field mapping
            MappingPanel mappingPanel = new MappingPanel(fieldtoFieldMapping);
            mappingPanel.setShowOnlyConnectedItems(true);
            int height = mappingPanel.getMinimumSize().height;
            mappingPanel.setSize(800, height);

            BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB);
            im.getGraphics().setColor(Color.WHITE);
            im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight());
            mappingPanel.paint(im.getGraphics());
            document.addPicture(im, 600, height * 6 / 8);

            // Add table of field to field mapping
            XWPFTable table = document.createTable(fieldtoFieldMapping.getTargetItems().size() + 1, 4);
            // table.setWidth(2000);
            XWPFTableRow header = table.getRow(0);
            setTextAndHeaderShading(header.getCell(0), "Destination Field");
            setTextAndHeaderShading(header.getCell(1), "Source Field");
            setTextAndHeaderShading(header.getCell(2), "Logic");
            setTextAndHeaderShading(header.getCell(3), "Comment");
            int rowNr = 1;
            for (MappableItem targetField : fieldtoFieldMapping.getTargetItems()) {
                XWPFTableRow row = table.getRow(rowNr++);
                row.getCell(0).setText(targetField.getName());

                StringBuilder source = new StringBuilder();
                StringBuilder logic = new StringBuilder();
                StringBuilder comment = new StringBuilder();
                for (ItemToItemMap fieldToFieldMap : fieldtoFieldMapping.getSourceToTargetMaps()) {
                    if (fieldToFieldMap.getTargetItem() == targetField) {
                        if (source.length() != 0)
                            source.append("\n");
                        source.append(fieldToFieldMap.getSourceItem().getName().trim());

                        if (logic.length() != 0)
                            logic.append("\n");
                        logic.append(fieldToFieldMap.getLogic().trim());

                        if (comment.length() != 0)
                            comment.append("\n");
                        comment.append(fieldToFieldMap.getComment().trim());
                    }
                }

                for (Field field : targetTable.getFields()) {
                    if (field.getName().equals(targetField.getName())) {
                        if (comment.length() != 0)
                            comment.append("\n");
                        comment.append(field.getComment().trim());
                    }
                }

                createCellParagraph(row.getCell(1), source.toString());
                createCellParagraph(row.getCell(2), logic.toString());
                createCellParagraph(row.getCell(3), comment.toString());
            }
        }

}

From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java

License:Apache License

private static void addTableLevelSection(CustomXWPFDocument document, ETL etl)
        throws InvalidFormatException, FileNotFoundException {
    XWPFParagraph tmpParagraph = document.createParagraph();
    XWPFRun tmpRun = tmpParagraph.createRun();

    MappingPanel mappingPanel = new MappingPanel(etl.getTableToTableMapping());
    mappingPanel.setShowOnlyConnectedItems(true);
    int height = mappingPanel.getMinimumSize().height;
    mappingPanel.setSize(800, height);/*from  w w w .  j a v  a2  s.c  o m*/

    tmpRun.setText(
            mappingPanel.getSourceDbName() + " Data Mapping Approach to " + mappingPanel.getTargetDbName());
    tmpRun.setFontSize(18);

    BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB);
    im.getGraphics().setColor(Color.WHITE);
    im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight());
    mappingPanel.paint(im.getGraphics());
    document.addPicture(im, 600, height * 6 / 8);
}

From source file:org.robert.study.service.merge.doc.SimpleDocument.java

License:Apache License

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

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);//from  w  w w . j  ava 2 s .co  m
    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("z://simple.docx");
    doc.write(out);
    out.close();

}

From source file:ParserDoc.SimpleDocument.java

License:Apache License

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

    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);/*  w ww . j  a v  a 2  s . c  o  m*/
    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.setStrikeThrough(true);
    r2.setFontSize(20);

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

    XWPFParagraph p3 = doc.createParagraph();
    // p3.setWordWrapped(true);
    p3.setPageBreak(true);

    //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
    p3.setAlignment(ParagraphAlignment.BOTH);
    // p3.setSpacingBetween(15, 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();
    // out.close ();
}

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

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

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

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

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

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

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

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

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

        }

        XWPFParagraph paragraph = document.createParagraph();

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

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

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

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

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

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

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

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

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

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

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

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();/*from   w w w. j  a  va  2s .  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:service.Read_Write_File.java

public void SetDOCX_DT(List<Bordereau> bordereaus, List<CorpDetat> corpDetats, List<ArticleChp1> articlechp1s,
        List<ArticleChp2> articlechp2s) throws Exception {

    //    XWPFDocument document = new XWPFDocument(); //creete a new documment 
    XWPFDocument doc = new XWPFDocument();

    //FileInputStream is = new FileInputStream("D:\\a.jpg"); 

    // doc.addPictureData(IOUtils.toByteArray(fs), doc.PICTURE_TYPE_JPEG);

    //doc.create(id,doc.getNextPicNameNumber(doc.PICTURE_TYPE_JPEG), 64, 64);
    XWPFParagraph para2 = doc.createParagraph();
    para2.setAlignment(ParagraphAlignment.CENTER);
    XWPFRun run = para2.createRun();
    run.setBold(true);//  ww  w  .  ja  v a 2s  . com
    run.setFontSize(40);

    // run.addPicture(pic, doc.PICTURE_TYPE_JPEG, "3", 0, 0);

    // run.addPicture(fs, doc.PICTURE_TYPE_JPEG, blipId, 100, 100);
    //  run.addPicture(is,2, "kamal", 20, 20);
    //run.addPicture(IOUtils.toByteArray(is), doc.PICTURE_TYPE_JPEG);
    run.setText("\n \t Descriptif technique  \n ");

    // pour article d projet
    XWPFParagraph para3 = doc.createParagraph();
    // para2.setAlignment(ParagraphAlignment.CENTER);
    run = para3.createRun();
    run.setText(" I- article de votre projet :");
    run.setFontSize(18);
    run.setBold(true);

    XWPFParagraph para4 = doc.createParagraph();// pour les article chp 1
    run = para4.createRun();
    run.setText("    I-1 article chapitre1   :   \n");
    run.setFontSize(14);
    run.setBold(true);
    run.addBreak();

    int i = 1;
    for (ArticleChp1 loadarticlechp1 : articlechp1s) {// kan3amar text1 dyal articlchp1
        run = para4.createRun();
        run.setText("      " + i + ")- " + loadarticlechp1.getTitre());
        run.addBreak();
        i++;
    }
    XWPFParagraph para5 = doc.createParagraph(); // pour les articles chp2
    run = para5.createRun();
    run.setText("    I-2 article chapitre2   :   \n");
    run.setFontSize(14);
    run.setBold(true);
    run.addBreak();
    i = 1;
    for (ArticleChp2 loadarticlechp2 : articlechp2s) {// text2 dyla articlechp2
        run = para5.createRun();
        run.setText("       " + i + ")- " + loadarticlechp2.getTitre());
        run.addBreak();
        i++;
    }

    // corpdetat de projet
    XWPFParagraph para6 = doc.createParagraph();
    // para2.setAlignment(ParagraphAlignment.CENTER);
    run = para6.createRun();
    run.setText("\t II- corps dtat :");
    run.setFontSize(18);
    run.setBold(true);
    run.addBreak();
    //  run.setColor("#999");

    i = 1;
    // bouclage pourles coprs et posts dyal kola corps 
    for (CorpDetat loaDetat : corpDetats) {
        run = para6.createRun();
        run.setText("       II-" + i + "- " + loaDetat.getTitre() + "  : ");
        run.setFontSize(16);

        run.addBreak();

        int j = 1;
        for (Post loadpost : loaDetat.getPosts()) {
            run = para6.createRun();
            run.setText("                 " + i + "-" + j + ")  " + loadpost.getTitre() + " ");
            run.addBreak();
            j++;
        }
        i++;
    }

    // 
    // bordeauraux
    XWPFParagraph para = doc.createParagraph();

    run = para.createRun();
    run.setBold(true);
    run.setFontSize(18);
    run.setText("     bordereau de prix ");
    run.addBreak();
    run = para.createRun();

    //Creates a table 
    XWPFTable tab = doc.createTable();
    tab.setWidth(500);

    tab.setCellMargins(50, 200, 50, 200);

    XWPFTableRow row1 = tab.getRow(0);

    row1.getCell(0).setText("designation");
    row1.getCell(0).setColor("FF9900");

    row1.addNewTableCell().setText("Unite");
    row1.getCell(1).setColor("FF9900");

    row1.addNewTableCell().setText("Quantite");
    row1.getCell(2).setColor("FF9900");

    row1.addNewTableCell().setText("prix");
    row1.getCell(3).setColor("FF9900");

    row1.addNewTableCell().setText("montant");
    row1.getCell(4).setColor("FF9900");
    i = 1;
    for (Bordereau loadbordereau : bordereaus) {

        XWPFTableRow loadRow = null;
        loadRow = tab.createRow();

        loadRow.getCell(0).setText(loadbordereau.getDesignation() + "");
        loadRow.getCell(1).setText(loadbordereau.getUnite());
        if (loadbordereau.getQuanite() == 0) {
            loadRow.getCell(2).setText("");

        } else {
            loadRow.getCell(2).setText(loadbordereau.getQuanite() + "");
        }
        if (loadbordereau.getPrix() == 0) {
        } else {
            loadRow.getCell(3).setText(loadbordereau.getPrix() + "");
        }
        if (loadbordereau.getMontant() == 0.0) {
        } else {
            loadRow.getCell(4).setText(loadbordereau.getMontant() + "");
        }

    }

    XWPFTableRow row3 = null;
    row3 = tab.createRow();
    row3.getCell(0).setText("TVA");
    row3.getCell(0).setColor("FF9900");

    XWPFTableRow row4 = null;
    row4 = tab.createRow();
    row4.getCell(0).setText("HTTC");
    row4.getCell(0).setColor("FF9900");

    try {
        doc.write(new FileOutputStream("D:\\test2.docx"));
        // InputStream pica = new FileInputStream("D:\\test2.docx");
        //FileInputStream fis = new FileInputStream("D:\\test2.docx");
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(new File("D:\\test2.docx"));
        }
    } catch (IOException ex) {

    }

}