Example usage for org.apache.poi.openxml4j.opc PackageProperties setTitleProperty

List of usage examples for org.apache.poi.openxml4j.opc PackageProperties setTitleProperty

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.opc PackageProperties setTitleProperty.

Prototype

void setTitleProperty(Optional<String> title);

Source Link

Document

Set the name given to the resource.

Usage

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

License:Open Source License

/**
 * Sets a document property of the currently exported document
 * /*from   w w w.ja  va2  s  .co m*/
 * @created 11.02.2014
 * @param key the property key to be set
 * @param value the property value to be set
 */
public void setProperty(String key, String value) {
    try {
        PackageProperties properties = document.getPackage().getPackageProperties();
        if (Strings.equalsIgnoreCase("author", key) || Strings.equalsIgnoreCase("autor", key)) {
            properties.setCreatorProperty(Strings.trim(value));
        } else if (Strings.equalsIgnoreCase("title", key) || Strings.equalsIgnoreCase("titel", key)) {
            properties.setTitleProperty(Strings.trim(value));
        } else if (Strings.equalsIgnoreCase("version", key) || Strings.equalsIgnoreCase("revision", key)) {
            document.getProperties().getCoreProperties().setRevision(value);
        } else if (Strings.equalsIgnoreCase("project", key) || Strings.equalsIgnoreCase("projekt", key)
                || Strings.equalsIgnoreCase("subject", key) || Strings.equalsIgnoreCase("betreff", key)) {
            properties.setSubjectProperty(Strings.trim(value));
        }

        // always add as custom property
        setCustomProperty(key, value);
    } catch (InvalidFormatException e) {
        addMessage(Messages.warning("unexpected format exception"));
    }
}

From source file:poitest.TemplateConvert.java

License:Open Source License

public static void main(String[] args) throws Exception {
    ExportManager export = new ExportManager(null);
    ExportModel model = new ExportModel(export, ExportManager.createDefaultTemplateStream());
    DefaultBuilder builder = new DefaultBuilder(model);

    XWPFRun run = builder.getParagraph(Style.text).createRun();
    run.setText("Hallo Welt!\n");

    run = builder.getNewParagraph(Style.heading1).createRun();
    run.setText("Hallo berschrift\n");

    run = builder.getParagraph(Style.text).createRun();
    run.setText(//from  w ww .jav a 2  s.  c  o m
            "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n");

    run = builder.getNewParagraph(Style.heading2).createRun();
    run.setText("Und etwas kleiner\n");

    run = builder.getNewParagraph(Style.heading3).createRun();
    run.setText("Und noch kleiner\n");

    run = builder.getNewParagraph(Style.heading2).createRun();
    run.setText("Und etwas kleiner\n");

    PackageProperties properties = builder.getDocument().getPackage().getPackageProperties();
    properties.setRevisionProperty("13");
    properties.setCreatorProperty("Volker POI");
    properties.setTitleProperty("MMP Qatar Test Document");

    File folder = new File("target/result");
    folder.mkdirs();
    try (FileOutputStream stream = new FileOutputStream(new File(folder, "Test.docx"))) {
        builder.getDocument().write(stream);
    }
    System.out.println("Done.");
    Exec.runSimpleCommand("open Test.docx", folder);
}