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

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

Introduction

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

Prototype

public void setText(String value) 

Source Link

Document

Sets the text of this text run

Usage

From source file:de.knowwe.include.export.FootnoteExporter.java

License:Open Source License

@Override
public void export(Section<FootnoteType> section, DocumentBuilder manager) throws ExportException {
    // find id for our footnote
    String refNumber = section.get().getFootnoteID(section);
    BigInteger noteId = getFootnoteIDInternal(manager, section.getArticle(), refNumber);

    // create footnote for that id
    CTFtnEdn ctNote = CTFtnEdn.Factory.newInstance();
    ctNote.setId(noteId);//  ww w . j  a v a2 s.  c o  m
    ctNote.setType(STFtnEdn.NORMAL);
    XWPFFootnotes footnotes = manager.getDocument().createFootnotes();
    XWPFFootnote footnote = footnotes.addFootnote(ctNote);

    // add contents to footer
    XWPFParagraph footPara = footnote.addNewParagraph(CTP.Factory.newInstance());
    footPara.setStyle(Style.footnote.getStyleName());
    XWPFRun footRun = footPara.createRun();
    footRun.setSubscript(VerticalAlign.SUPERSCRIPT);
    footRun.setText(String.valueOf(noteId.intValue()));
    footRun = footPara.createRun();
    footRun.setSubscript(VerticalAlign.BASELINE);
    DocumentBuilder contentBuilder = new ListBuilder(manager, footPara, Style.text);
    contentBuilder.export(section.getChildren());
}

From source file:de.knowwe.include.export.FootnoteReferenceExporter.java

License:Open Source License

@Override
public void export(Section<LinkType> section, DocumentBuilder manager) throws ExportException {
    // find id for our footnote
    String refNumber = LinkType.getLink(section);

    // add reference to text
    XWPFRun run = manager.getParagraph().createRun();
    run.setSubscript(VerticalAlign.SUPERSCRIPT);
    Article article = section.getArticle();
    String label = getForcedLabel(manager, article, refNumber);
    if (label == null) {
        // add reference to footnote
        CTFtnEdnRef textRef = run.getCTR().addNewFootnoteReference();
        BigInteger noteId = FootnoteExporter.getFootnoteID(manager, article, refNumber);
        textRef.setId(noteId);/*  w  w  w  . j  a  v  a 2s  . c  o m*/
        addForcedLabel(article, refNumber, String.valueOf(noteId));
    } else {
        // otherwise only add text in similar style
        run.setText(label);
        addForcedLabel(article, refNumber, label);
    }
}

From source file:de.knowwe.include.export.ImageExporter.java

License:Open Source License

@Override
public void export(Section<PluginType> section, DocumentBuilder manager) throws ExportException {
    String file = Strings.trim(attr(section, "src"));
    if (Strings.isBlank(file)) {
        throw new ExportException(
                "cannot export image: " + "'src' does not contain a file name in " + section.getText());
    }//from w ww .j  a v a2  s  . c  om
    try {
        String title = section.getTitle();
        String path;
        if (file.startsWith("attach/")) {
            // image tag uses verbose image url: attach/article/image
            path = file.substring(file.indexOf('/') + 1);
        } else if (file.contains("/")) {
            // image tag uses article/image
            path = file;
        } else {
            // image tag uses only image name, relative to current article
            path = title + "/" + file;
        }
        WikiConnector connector = Environment.getInstance().getWikiConnector();
        WikiAttachment attachment = connector.getAttachment(path);

        Dimension dim = getImageDimension(section, attachment);
        try (InputStream stream = attachment.getInputStream()) {
            XWPFRun run = manager.getNewParagraph(Style.image).createRun();
            MyXWPFRun.addPicture(run, stream, getFormat(path), file, Units.toEMU(dim.width),
                    Units.toEMU(dim.height));
        }

        String caption = attr(section, "caption");
        if (!Strings.isBlank(caption)) {
            XWPFRun run = manager.getNewParagraph(Style.caption).createRun();
            run.setText(caption);
        }
    } catch (InvalidFormatException e) {
        throw new ExportException("Image has invalid format: " + file, e);
    } catch (Exception e) {
        throw new ExportException("Could not load image: " + file, e);
    }
}

From source file:de.knowwe.include.export.InlineDefinitionExporter.java

License:Open Source License

@Override
public void export(Section<InlineDefinitionType> section, DocumentBuilder manager) throws ExportException {
    ExportUtils.addRequiredSpace(manager);
    String refID = HeaderExporter.getCrossReferenceID(section);
    XWPFRun run = HeaderExporter.createCrossReferenceRun(refID, manager);
    run.setColor("606060");
    run.setFontSize(7);//  w w w.  j a v a 2s. c om

    run.setText("(");
    run.setText(section.get().getHeadText(section));
    run.setText(": ");

    manager.export(section.get().getDataSection(section));

    run = manager.getParagraph().createRun();
    run.setColor("606060");
    run.setFontSize(7);
    run.setText(")");

    run = manager.getParagraph().createRun();
    run.setText(" ");
}

From source file:de.micromata.tpsb.doc.renderer.MicrosoftWordRenderer.java

License:Apache License

/**
 * Fgt einzele Tests aus einem Test-Case hinzu
 * //  w w  w  . j a  va2 s. com
 * @param fInfo the file information
 */
private void addTestMethods(FileInfo fInfo) {
    for (MethodInfo mInfo : fInfo.getMethodInfos()) {
        addH2(mInfo.getMethodName());

        // Java-Doc Test-Methode
        if (mInfo.getJavaDocInfo() != null && mInfo.getJavaDocInfo().getTitle() != null) {
            addPar("Testbeschreibung", mInfo.getJavaDocInfo().getTitle());
        }

        // Autoren
        if (mInfo.getJavaDocInfo() != null && mInfo.getJavaDocInfo().getTagInfo("@author") != null
                && mInfo.getJavaDocInfo().getTagInfo("@author").isEmpty() == false) {
            List<String> authors = new ArrayList<String>();
            for (Pair<String, String> author : mInfo.getJavaDocInfo().getTagInfo("@author")) {
                authors.add(author.getSecond());
            }
            addPar("Autoren Tests", authors.toArray(new String[authors.size()]));
        }
        addPar("Testablauf", mInfo.getTestSteps().size() == 0 ? "Keine Daten" : "");

        // Parameter in neue Zeilen hinzufgen
        XWPFTable testStepTable = document.createTable();
        setTableStyle(testStepTable, "TabelleProfessionell");
        XWPFTableRow headRow = testStepTable.getRow(0);
        headRow.getCell(0).setText("#");
        headRow.addNewTableCell().setText("Vorgehen");

        for (TestStepInfo tInfo : mInfo.getTestSteps()) {
            XWPFTableRow row = testStepTable.createRow();
            setColor("EDEDED", row.getCell(0).getCTTc()); // graue steps
            setColor("EDEDED", row.getCell(1).getCTTc());
            row.getCell(0).setText("#" + tInfo.getTestStep());
            if (tInfo.getTbJavaDocInfo() != null) {
                row.getCell(1).setText(tInfo.getTbJavaDocInfo().getTitle());
            } else {
                row.getCell(1).setText("Keine Daten");
            }

            // Aufrufparameter
            if (tInfo.getParameters() != null && tInfo.getParameters().isEmpty() == false) {
                for (ParameterInfo pInfo : tInfo.getParameters()) {
                    XWPFTableRow pRow = testStepTable.createRow();
                    XWPFParagraph p = pRow.getCell(1).getParagraphs().get(0);
                    XWPFRun pRun = p.createRun();
                    pRun.setText(pInfo.getJavaDoc() + ": " + pInfo.getParamValue());
                    pRow.getCell(1).addParagraph(p);
                }
            }
        }

        // Falls vorhanden auch Screenshots in die Doku aufnehmen
        addScreenShotsIfExists(mInfo);
    }
}

From source file:de.micromata.tpsb.doc.renderer.MicrosoftWordRenderer.java

License:Apache License

/**
 * Fgt eine berschrift 1. Ebene ein/*www . j  a  va 2  s. com*/
 * 
 * @param heading
 *            der Titel
 */
private void addH1(String heading) {
    XWPFParagraph headPar = document.createParagraph();
    headPar.setStyle("berschrift1");
    XWPFRun run = headPar.createRun();
    run.setText(heading);
}

From source file:de.micromata.tpsb.doc.renderer.MicrosoftWordRenderer.java

License:Apache License

/**
 * Fgt eine berschrift 2. Ebene ein/*  w ww.  j  a va  2s  .  c o m*/
 * 
 * @param heading
 *            der Titel
 */
private void addH2(String heading) {
    XWPFParagraph headPar = document.createParagraph();
    headPar.setStyle("berschrift2");
    XWPFRun run = headPar.createRun();
    run.setText(heading);
}

From source file:de.micromata.tpsb.doc.renderer.MicrosoftWordRenderer.java

License:Apache License

/**
 * Fgt einen neuen Paragraphen ein./*from  ww  w . jav  a2  s  . c om*/
 * 
 * @param title
 *            Titel des Abschnitts
 * @param content
 *            Inhalt (mehrere Zeilen mglich)
 */
private void addPar(String title, String... content) {
    XWPFParagraph par = document.createParagraph();
    XWPFRun titleRun = par.createRun();
    titleRun.setBold(true);
    titleRun.addCarriageReturn();
    titleRun.setText(title);
    titleRun.addCarriageReturn();
    for (String line : content) {
        XWPFRun contentRun = par.createRun();
        contentRun.setText(line);
    }
}

From source file:demo.poi.image.SimpleImages.java

License:Apache License

static void writeImageToDoc(String[] args) throws InvalidFormatException, IOException, FileNotFoundException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();

    XWPFRun r = p.createRun();

    for (String imgFile : args) {
        int format;

        if (imgFile.endsWith(".emf"))
            format = XWPFDocument.PICTURE_TYPE_EMF;
        else if (imgFile.endsWith(".wmf"))
            format = XWPFDocument.PICTURE_TYPE_WMF;
        else if (imgFile.endsWith(".pict"))
            format = XWPFDocument.PICTURE_TYPE_PICT;
        else if (imgFile.endsWith(".jpeg") || imgFile.endsWith(".jpg"))
            format = XWPFDocument.PICTURE_TYPE_JPEG;
        else if (imgFile.endsWith(".png"))
            format = XWPFDocument.PICTURE_TYPE_PNG;
        else if (imgFile.endsWith(".dib"))
            format = XWPFDocument.PICTURE_TYPE_DIB;
        else if (imgFile.endsWith(".gif"))
            format = XWPFDocument.PICTURE_TYPE_GIF;
        else if (imgFile.endsWith(".tiff"))
            format = XWPFDocument.PICTURE_TYPE_TIFF;
        else if (imgFile.endsWith(".eps"))
            format = XWPFDocument.PICTURE_TYPE_EPS;
        else if (imgFile.endsWith(".bmp"))
            format = XWPFDocument.PICTURE_TYPE_BMP;
        else if (imgFile.endsWith(".wpg"))
            format = XWPFDocument.PICTURE_TYPE_WPG;
        else {/*  ww  w  .j a  v  a 2s .c o  m*/
            System.err.println("Unsupported picture: " + imgFile
                    + ". Expected emf|wmf|pict|jpeg|png|dib|gif|tiff|eps|bmp|wpg");
            continue;
        }

        r.setText(imgFile);
        r.addBreak();
        r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200
        // pixels
        r.addBreak(BreakType.PAGE);
    }

    FileOutputStream out = new FileOutputStream("images.docx");
    doc.write(out);
    out.close();
    // doc.close();
}

From source file:editordetext.IO.java

public void save(String txt) {
    if (!path.equals("")) {
        switch (fileType) {
        case "txt":
            ArrayList<String> lines = new ArrayList();
            Path file = Paths.get(path);
            lines.add(txt);/* ww  w.j  ava2 s  .  co m*/
            try {
                Files.write(file, lines, Charset.forName("UTF-8"));
            } catch (IOException ex) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
            }
            break;
        case "Word":
            XWPFDocument document = new XWPFDocument();
            try {
                FileOutputStream out = new FileOutputStream(new File(path));
                XWPFParagraph paragraph = document.createParagraph();
                XWPFRun run = paragraph.createRun();
                run.setText(txt);
                document.write(out);
                out.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
            }
            break;
        case "PDF":
            try {
                Document pdf = new Document();
                PdfWriter.getInstance(pdf, new FileOutputStream(path));
                pdf.open();
                pdf.add(new Paragraph(txt));
                pdf.close();
            } catch (DocumentException | FileNotFoundException ex) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
            }
            break;
        }
    } else {
        new Save().setVisible(true);
    }
}