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:MainPackage.Controllers.BookController.java

private XWPFParagraph createPrintInformation(XWPFDocument document, Account _account) {
    XWPFParagraph paragraph = document.createParagraph();

    paragraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun run = createFieldRun(paragraph, "Ngy in: ");
    run.setFontSize(10);
    run = createValueRun(paragraph, getCurrentDateString());
    run.setFontSize(10);/*from  ww w. j a  v a  2s .c o m*/
    run.addCarriageReturn();
    run = createFieldRun(paragraph, "Th?i gian in: ");
    run.setFontSize(10);
    run = createValueRun(paragraph, getCurrentTimeString());
    run.setFontSize(10);
    run.addCarriageReturn();
    run = createFieldRun(paragraph, "Ti khon in: ");
    run.setFontSize(10);
    run = createValueRun(paragraph, _accountProvider.getById(_account.getId()).getUsername());
    run.setFontSize(10);
    run.addCarriageReturn();

    return paragraph;
}

From source file:MainPackage.Controllers.BookController.java

private XWPFParagraph createBookProductInformation(XWPFDocument document, BookViewModel bookView) {
    XWPFParagraph paragraph = document.createParagraph();

    paragraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun run = createFieldRun(paragraph, "Thng tin Sn phm: ");
    run.setFontSize(16);
    run.addCarriageReturn();//from w w w . j av a 2s . c  om

    ArrayList<PrintRunField> productInformations = new ArrayList<PrintRunField>() {
        {
            add(new PrintRunField("M sch: ", bookView.IdCode));
            add(new PrintRunField("M ISBN: ", bookView.ISBN));
            add(new PrintRunField("Ti khon to: ", bookView.CreatedBy));
            add(new PrintRunField("Th?i gian to: ", bookView.CreateTime));
            add(new PrintRunField("Gi sch: ", bookView.Price));
            add(new PrintRunField("Tnh trng: ", bookView.Status));
        }
    };

    for (int i = 0; i < productInformations.size(); i++) {

        run = createFieldRun(paragraph, productInformations.get(i).Field);
        run.addTab();
        run = createValueRun(paragraph, productInformations.get(i).Value);
        if (i % 2 == 0) {
            run.addTab();
        } else {
            run.addCarriageReturn();
        }
    }

    return paragraph;
}

From source file:MainPackage.Controllers.BookController.java

private XWPFParagraph createBookInformation(XWPFDocument document, BookViewModel bookView) {
    XWPFParagraph paragraph = document.createParagraph();

    XWPFRun run = createFieldRun(paragraph, "Thng tin Sch: ");
    run.setFontSize(16);
    run.addCarriageReturn();/*from w  w  w  .  ja va 2  s  . com*/

    ArrayList<PrintRunField> bookInformations = new ArrayList<PrintRunField>() {
        {
            add(new PrintRunField("Tn sch: ", bookView.Name));
            add(new PrintRunField("Tc gi: ", bookView.Author));
            add(new PrintRunField("Nh xut bn: ", bookView.Publisher));
            add(new PrintRunField("Th loi: ", bookView.Type));
            add(new PrintRunField("Pht hnh: ", bookView.PublishMonth + "/" + bookView.PublishYear));
            add(new PrintRunField("M t:      ", bookView.Details));
        }
    };

    for (PrintRunField bookInformation : bookInformations) {
        run = createFieldRun(paragraph, bookInformation.Field);
        run.addTab();
        run = createValueRun(paragraph, bookInformation.Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:MainPackage.Controllers.OrderController.java

public void Print(Frame frame, Orders order, Account _account) {
    try {/*w w w.  j a v a  2 s  .co m*/
        XWPFDocument document = new XWPFDocument();
        File file = new File("Ha n " + order.getIdCode() + ".doc");
        if (file.exists()) {
            file.createNewFile();
        }

        FileOutputStream out = new FileOutputStream(file);

        XWPFParagraph paragraph = document.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);

        XWPFRun run;
        //            BookViewModel bookView = new BookViewModel(book);

        /////////////////
        run = createFieldRun(paragraph, "CHI TIT HA ?N");
        run.setFontSize(24);

        paragraph = createPrintInformation(document, _account);
        paragraph = createBookProductInformation(document, order);
        paragraph = createBookInformation(document, order);

        //create table
        XWPFTable table = document.createTable();
        setTableAlignment(table, STJc.CENTER);
        table.setCellMargins(50, 50, 50, 50);
        table.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 10, 10, "");
        table.setInsideVBorder(XWPFTable.XWPFBorderType.NONE, 20, 20, "");
        //create first row
        XWPFTableRow row = table.getRow(0);
        row.setHeight(40);
        row.getCell(0).setText("STT");
        row.addNewTableCell().setText("M Sn phm");
        row.addNewTableCell().setText("Tn Sn phm");
        row.addNewTableCell().setText("?n v");
        row.addNewTableCell().setText("S lng");
        row.addNewTableCell().setText("Gi ti?n");
        row.addNewTableCell().setText("Thnh ti?n");

        List<OrderLine> list = (List<OrderLine>) order.getOrderLineCollection();
        for (int i = 0; i < list.size(); i++) {
            OrderLine line = list.get(i);

            row = table.createRow();
            row.getCell(0).setText((i + 1) + "");
            row.getCell(1).setText(line.getProductId().getIdCode());
            row.getCell(2).setText(line.getProductId().getName());
            row.getCell(3).setText("Quyn     ");
            row.getCell(4).setText(line.getQuantity() + "     ");
            row.getCell(5).setText(IntToVND(line.getUnitPrice()) + "     ");
            row.getCell(6).setText(IntToVND(line.getTotalPrice()) + "     ");
        }

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

        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(file);
        }

        JOptionPane
                .showMessageDialog(frame,
                        "Xut file " + file.getName() + " thnh cng" + '\n' + "Ti v tr: "
                                + file.getAbsolutePath(),
                        "In thng tin Ha n", JOptionPane.INFORMATION_MESSAGE);

    } catch (Exception e) {
        System.out.println(e);

        JOptionPane.showMessageDialog(frame,
                "Xut file tht bi." + '\n' + "Vui lng ng ca s ang s dng file",
                "In thng tin Ha n", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:MainPackage.Controllers.OrderController.java

private XWPFParagraph createBookProductInformation(XWPFDocument document, Orders order) {
    XWPFParagraph paragraph = document.createParagraph();

    paragraph.setAlignment(ParagraphAlignment.LEFT);
    XWPFRun run = createFieldRun(paragraph, "Thng tin Ha n: ");
    run.setFontSize(16);
    run.addCarriageReturn();/*from   w ww  .  j ava  2s. com*/

    ArrayList<BookController.PrintRunField> productInformations = new ArrayList<BookController.PrintRunField>() {
        {
            add(new BookController.PrintRunField("M Ha n: ", order.getIdCode()));
            add(new BookController.PrintRunField("Ti khon lp: ", order.getCreateBy().getUsername()));
            add(new BookController.PrintRunField("Th?i gian lp: ",
                    getDateTimeString(order.getCreateTime())));
            add(new BookController.PrintRunField(" ", ""));
            add(new BookController.PrintRunField("Tng ti?n: ", IntToVND(order.getTotalPrice())));
            add(new BookController.PrintRunField("Thu VAT: ", IntToVND(order.getVATPrice())));
            add(new BookController.PrintRunField("Khuyn mi: ", IntToVND(order.getDiscount())));
            add(new BookController.PrintRunField("Thanh ton: ", IntToVND(order.getPaidPrice())));
        }
    };

    for (int i = 0; i < productInformations.size(); i++) {

        run = createFieldRun(paragraph, productInformations.get(i).Field);
        run.addTab();
        run = createValueRun(paragraph, productInformations.get(i).Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:MainPackage.Controllers.OrderController.java

private XWPFParagraph createBookInformation(XWPFDocument document, Orders order) {
    XWPFParagraph paragraph = document.createParagraph();

    XWPFRun run = createFieldRun(paragraph, "Thng tin Khch hng: ");
    run.setFontSize(16);
    run.addCarriageReturn();//from  w  w w.j ava  2  s  .  com

    ArrayList<BookController.PrintRunField> bookInformations = new ArrayList<BookController.PrintRunField>() {
        {
            add(new BookController.PrintRunField("Tn khch: ", order.getGuestName()));
            add(new BookController.PrintRunField("?a ch: ", order.getGuestPhone()));
            add(new BookController.PrintRunField("?in thoi: ", order.getGuestPhone()));
            add(new BookController.PrintRunField("Email:      ", order.getGuestEmail()));
            add(new BookController.PrintRunField(" ", ""));
            add(new BookController.PrintRunField("Ghi ch: ", order.getDetails()));
        }
    };

    for (BookController.PrintRunField bookInformation : bookInformations) {
        run = createFieldRun(paragraph, bookInformation.Field);
        run.addTab();
        run = createValueRun(paragraph, bookInformation.Value);
        run.addCarriageReturn();
    }

    return paragraph;
}

From source file:Management.Projects.java

public String CrearMinuta(String datos[], int idProject, String[] Asistentes, String[] puntos)
        throws IOException {
    String result = "";
    ArrayList<XWPFParagraph> listfecha = new ArrayList<>();
    ArrayList<XWPFParagraph> listasistentes = new ArrayList<>();
    ArrayList<XWPFParagraph> listpuntos = new ArrayList<>();
    XWPFDocument doc = new XWPFDocument();
    int i;//from w  w  w  .  j a  v  a  2s  .com
    XWPFParagraph p3;
    XWPFParagraph p1 = doc.createParagraph();
    p1.setAlignment(ParagraphAlignment.CENTER);
    p1.setBorderBottom(Borders.DOUBLE);
    p1.setBorderTop(Borders.DOUBLE);
    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("Datos de la minuta");
    r1.setBold(true);
    for (i = 0; i < datos.length; i++) {
        p3 = doc.createParagraph();
        listfecha.add(p3);

    }
    i = 0;
    for (XWPFParagraph para : listfecha) {
        XWPFRun r2 = para.createRun();
        r2.setText(datos[i]);
        r2.setFontSize(20);
        i++;
    }

    XWPFParagraph parrafoAsistentes = doc.createParagraph();
    parrafoAsistentes.setAlignment(ParagraphAlignment.CENTER);
    parrafoAsistentes.setBorderBottom(Borders.DOUBLE);
    parrafoAsistentes.setBorderTop(Borders.DOUBLE);
    XWPFRun r2 = parrafoAsistentes.createRun();
    r2.setBold(true);
    r2.setText("Asistentes:");
    r2.setBold(true);

    XWPFParagraph p4;
    for (i = 0; i < Asistentes.length; i++) {
        p4 = doc.createParagraph();
        listasistentes.add(p4);

    }

    i = 0;
    for (XWPFParagraph para : listasistentes) {
        XWPFRun r3 = para.createRun();
        r3.setText(Asistentes[i]);
        r3.setFontSize(20);
        i++;
    }

    XWPFParagraph parrafoPuntos = doc.createParagraph();
    parrafoPuntos.setAlignment(ParagraphAlignment.CENTER);
    parrafoPuntos.setBorderBottom(Borders.DOUBLE);
    parrafoPuntos.setBorderTop(Borders.DOUBLE);
    XWPFRun r3 = parrafoPuntos.createRun();
    r3.setBold(true);
    r3.setText("Puntos a Tratar:");
    r3.setBold(true);

    XWPFParagraph p5;
    for (i = 0; i < puntos.length; i++) {
        p5 = doc.createParagraph();
        listpuntos.add(p5);

    }
    i = 0;
    for (XWPFParagraph para : listpuntos) {
        XWPFRun r4 = para.createRun();
        r4.setText(puntos[i]);
        r4.setFontSize(20);
        i++;
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(System.getProperty("user.home")
                + "/Documents/NetBeansProjects/StickMaps/web/Minutas/Minuta" + idProject + ".docx");
    } catch (FileNotFoundException ex) {
        System.out.println(ex.toString());
        return ex.toString();
    }
    doc.write(out);
    result = "bien";
    out.close();

    return result;
}

From source file:nl.detoren.ijc.io.OutputIntekenlijst.java

License:Open Source License

public boolean export(Groepen groepen) {
    try {//from   ww  w  .  j a v  a 2  s  .  co m
        logger.log(Level.INFO, "Wedstrijden wegschrijven naar Excel");
        FileInputStream file = new FileInputStream("Leeg.docx");
        XWPFDocument document = new XWPFDocument(file);
        XWPFParagraph paragraph = document.getLastParagraph();
        setDoubleLineSpacing(paragraph);
        XWPFRun run = paragraph.createRun();
        run.setFontFamily("Courier New");
        run.setFontSize(12);
        String result;
        result = "Intekenlijst aangemaakt met " + IJCController.c().appTitle + " voor "
                + IJCController.c().verenigingNaam;
        run.setText(result);
        run.addCarriageReturn(); // separate previous text from break
        for (int i = 0; i < groepen.getAantalGroepen(); ++i) {
            if (i >= 1)
                run.addBreak();
            Groep groep = groepen.getGroepById(i);
            result = "Stand na " + groepen.getRonde() + "e ronde, " + groepen.getPeriode();
            result += "e periode                " + groep.getNaam() + " (" + groep.getSpelers().size() + ")\n";
            run.setText(result);
            run.addBreak();
            result = "    Naam                           ini   zw rating  gespeeld tegen  pnt\n";
            run.setText(result);
            run.addBreak();
            result = "-----------------------------------------------------------------------\n";
            run.setText(result);
            run.addBreak();
            for (Speler s : groep.getSpelers()) {
                result = s.toPrintableString(false);
                run.setText(result);
                run.addBreak();
            }

            if (IJCController.c().exportDoorschuivers) {
                int ndoor = IJCController.c().bepaalAantalDoorschuiversVolgendeRonde(groep.getNiveau(),
                        groepen.getPeriode(), groepen.getRonde());
                if (i - 1 >= 0) {
                    run.setText(IJCController.c().exportDoorschuiversStart + "\n");
                    run.addBreak();
                    Groep lager = groepen.getGroepById(i - 1);
                    if (ndoor > 1) {
                        for (int j = 0; j < ndoor; j++) {
                            Speler s = lager.getSpelerByID(j + 1);
                            run.setText(s.toPrintableString(false, true) + "\n");
                            run.addBreak();
                        }
                        run.setText(IJCController.c().exportDoorschuiversStop + "\n" + "\n");
                    } else {
                        // Bij n doorschuiver, alleen doorschuiven als
                        // kampioen
                        Speler s1 = lager.getSpelerByID(1);
                        Speler s2 = lager.getSpelerByID(2);
                        if ((s2 != null) && ((s1.getPunten() - s2.getPunten()) > 4)) {
                            run.setText(s1.toPrintableString(false, true) + "\n");
                            run.addBreak();
                        }

                    }
                }
            }
            run.addCarriageReturn(); // separate previous text from break
            run.addBreak(BreakType.PAGE);
        }
        // Close input file
        file.close();
        // Store Excel to new file
        String dirName = "R" + groepen.getPeriode() + "-" + groepen.getRonde();
        new File(dirName).mkdirs();
        String filename = dirName + File.separator + "IntekenlijstR" + groepen.getPeriode() + "-"
                + groepen.getRonde() + ".docx";
        File outputFile = new File(filename);
        FileOutputStream outFile = new FileOutputStream(outputFile);
        document.write(outFile);
        // Close output file
        document.close();
        outFile.close();
        // And open it in the system editor
        //Desktop.getDesktop().open(new File(outputFile));
        return true;
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Export mislukt :" + ex.getMessage());
        Utils.stacktrace(ex);
        return false;
    }
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>/*from   www .ja  v  a  2 s . c  o  m*/
 * Helper method to clone {@link XWPFRun}.
 * </p>
 * 
 * @param in
 * @param out
 * @param model
 */
public static void copy(XWPFRun in, XWPFRun out, UnaryOperator<String> converter) {
    // copy
    out.setBold(in.isBold());
    out.setCapitalized(in.isCapitalized());
    out.setCharacterSpacing(in.getCharacterSpacing());
    out.setColor(in.getColor());
    out.setDoubleStrikethrough(in.isDoubleStrikeThrough());
    out.setEmbossed(in.isEmbossed());
    out.setFontFamily(in.getFontFamily());
    out.setFontSize(in.getFontSize());
    out.setImprinted(in.isImprinted());
    out.setItalic(in.isItalic());
    out.setKerning(in.getKerning());
    out.setShadow(in.isShadowed());
    out.setSmallCaps(in.isSmallCaps());
    out.setStrikeThrough(in.isStrikeThrough());
    out.setVerticalAlignment(out.getVerticalAlignment().toString());
    out.setTextPosition(in.getTextPosition());
    out.setUnderline(in.getUnderline());

    // copy context
    CTR inCTR = in.getCTR();
    CTRPr inPR = inCTR.getRPr();
    CTR outCTR = out.getCTR();
    CTRPr outPR = outCTR.isSetRPr() ? outCTR.getRPr() : outCTR.addNewRPr();
    outPR.set(inCTR.getRPr());
    out.setVerticalAlignment(
            inPR == null || inPR.getVertAlign() == null ? "baseline" : inPR.getVertAlign().toString());

    // // copy tab
    // CTEmpty[] tabs = inCTR.getTabArray();
    //
    // if (tabs.length != 0) {
    // out.addTab();
    // }
    outCTR.setAnnotationRefArray(inCTR.getAnnotationRefList().toArray(CTEmpty[]::new));
    outCTR.setBrArray(inCTR.getBrList().toArray(CTBr[]::new));
    outCTR.setCommentReferenceArray(inCTR.getCommentReferenceList().toArray(CTMarkup[]::new));
    outCTR.setContinuationSeparatorArray(inCTR.getContinuationSeparatorList().toArray(CTEmpty[]::new));
    outCTR.setCrArray(inCTR.getCrList().toArray(CTEmpty[]::new));
    outCTR.setDelInstrTextArray(inCTR.getDelInstrTextList().toArray(CTText[]::new));
    outCTR.setDrawingArray(inCTR.getDrawingList().toArray(CTDrawing[]::new));
    outCTR.setEndnoteRefArray(inCTR.getEndnoteRefList().toArray(CTEmpty[]::new));
    outCTR.setFldCharArray(inCTR.getFldCharList().toArray(CTFldChar[]::new));
    outCTR.setFootnoteRefArray(inCTR.getFootnoteRefList().toArray(CTEmpty[]::new));
    outCTR.setInstrTextArray(inCTR.getInstrTextList().toArray(CTText[]::new));
    outCTR.setLastRenderedPageBreakArray(inCTR.getLastRenderedPageBreakList().toArray(CTEmpty[]::new));
    outCTR.setObjectArray(inCTR.getObjectList().toArray(CTObject[]::new));
    outCTR.setPictArray(inCTR.getPictList().toArray(CTPicture[]::new));
    outCTR.setPtabArray(inCTR.getPtabList().toArray(CTPTab[]::new));
    outCTR.setSymArray(inCTR.getSymList().toArray(CTSym[]::new));
    outCTR.setTabArray(inCTR.getTabList().toArray(CTEmpty[]::new));

    // copy image
    for (XWPFPicture inPicture : in.getEmbeddedPictures()) {
        try {
            XWPFPictureData inData = inPicture.getPictureData();
            String outId = out.getDocument().addPictureData(new ByteArrayInputStream(inData.getData()),
                    inData.getPictureType());

            select(CTBlip.class, outCTR).to(blip -> blip.setEmbed(outId));
        } catch (Exception e) {
            throw I.quiet(e);
        }
    }

    // copy text
    write(out, converter.apply(in.text()));
}

From source file:org.articleEditor.insertContent.DocumentUpdater1.java

License:Apache License

public void applyAttributes(XWPFRun run, AttributeSet attributes) {
    Enumeration attributeNames = attributes.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        Object attributeName = attributeNames.nextElement();
        Object attributeValue = attributes.getAttribute(attributeName);
        if (attributeName == Bold) {
            run.setBold((Boolean) attributeValue);
        } else if (attributeName == Italic) {
            run.setItalic((Boolean) attributeValue);
        } else if (attributeName == Underline) {
            run.setUnderline((Boolean) attributeValue ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE);
        } else if (attributeName == FontFamily || attributeName == Family) {
            run.setFontFamily((String) attributeValue);
        } else if (attributeName == FontSize) {
            run.setFontSize(((Number) attributeValue).intValue());
        } else if (attributeName == Foreground) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            run.setColor(rgb);//from  w w w.j  a  v a 2 s  .  c o  m
        } else if (attributeName == Background) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            //run.getCTR().getRPr().setHighlight();
        } else if (attributeName == Subscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == Superscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == StrikeThrough) {
            run.setStrike((Boolean) attributeValue);
        } else if (attributeName == Alignment) {
            ParagraphAlignment alignment = documentToPOI((Integer) attributeValue);
            run.getParagraph().setAlignment(alignment);
        }
    }
}