Examples of DemoCore


Examples of org.openxml4j.samples.DemoCore

* @version 1.0
*/
public class ListAllParts {

  public static void main(String[] args) throws Exception {
    DemoCore demoCore = new DemoCore();
    String filepath = demoCore.getTestRootPath() + "sample.docx";

    Package p = Package.open(filepath, PackageAccess.READ);
    for (PackagePart part : p.getParts())
      System.out.println(part.getPartName() + " -> "
          + part.getContentType());
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

* @version 0.1
*/
public class CreateWordprocessingMLDocument {

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

    File outputDocument = new File(demoCore.getTestRootPath()
        + "sample_output.docx");

    // Create a package
    Package pkg = Package.create(outputDocument);

View Full Code Here

Examples of org.openxml4j.samples.DemoCore

* @version 1.0
*/
public class GetCorePropertiesPart {

  public static void main(String[] args) {
    DemoCore demoCore = new DemoCore();

    try {
      // Open the package
      Package p = Package.open(
          demoCore.getTestRootPath() + "sample.docx",
          PackageAccess.READ);

      // Get documents core properties part relationship
      PackageRelationship corePropertiesRelationship = p
          .getRelationshipsByType(
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

*/
public class ModifyXMLContentWordprocessingMLDocument {

  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws Exception {
    DemoCore demoCore = new DemoCore();

    // Open the package
    Package pkg = Package.open(demoCore.getTestRootPath() + "sample.docx",
        PackageAccess.READ_WRITE);

    // Get documents core document part relationship
    PackageRelationship coreDocumentRelationship = pkg
        .getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT)
        .getRelationship(0);

    // Get core document part from the relationship.
    PackagePart coreDocumentPart = pkg.getPart(coreDocumentRelationship);

    InputStream inStream = coreDocumentPart.getInputStream();
    SAXReader docReader = new SAXReader();
    Document doc = docReader.read(inStream);

    Namespace namespaceWordProcessingML = new Namespace("w",
        "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
    Element bodyElement = doc.getRootElement().element(
        new QName("body", namespaceWordProcessingML));

    // Retrieves paragraph childs from body element
    List paragraphs = bodyElement.content();

    // Build a new paragraph element
    Element paragraph = DocumentHelper.createElement(new QName("p",
        namespaceWordProcessingML));
    Element run = paragraph.addElement(new QName("r",
        namespaceWordProcessingML));
    Element text = run
        .addElement(new QName("t", namespaceWordProcessingML));
    text.setText("New paragraph added with OpenXML4J !");

    // Add the newly created paragraph at the last position of paragraph
    // elements, just before the w:sectPr element
    paragraphs.add(paragraphs.size() - 1, paragraph);

    // Save back the content into the part
    StreamHelper.saveXmlInStream(doc, coreDocumentPart.getOutputStream());

    pkg.save(new File(demoCore.getTestRootPath() + "sample_output.docx"));
  }
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

* @version 0.1
*/
public class SetDocumentCoreProperties {

  public static void main(String[] args) {
    DemoCore demoCore = new DemoCore();

    // Destination file
    File destFile = new File(demoCore.getTestRootPath() + "sample_output.docx");

    // Open package
    Package pkg;
    try {
      pkg = Package.open(demoCore.getTestRootPath() + "sample.docx",
          PackageAccess.READ_WRITE);

      PackageProperties coreProps = pkg.getPackageProperties();
      coreProps.setCreatorProperty("Test Creator");
      coreProps.setDescriptionProperty("A new description !");
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

* @version 0.1
*/
public class ExtractPackageCoreProperties {

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

    String docPath;
    if (args.length == 1) {
      docPath = demoCore.getTestRootPath() + args[0];
    } else {
      docPath = demoCore.getTestRootPath() + "sample.docx";
    }

    try {
      // Open the package
      Package p = Package.open(docPath, PackageAccess.READ);
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

      return null;
    }
  }

  public static void main(String[] args) {
    DemoCore demoCore = new DemoCore();
    GetCorePart demo = new GetCorePart();

    String docPath;
    if (args.length == 1) {
      docPath = demoCore.getTestRootPath() + args[0];
    } else {
      docPath = demoCore.getTestRootPath() + "sample.docx";
    }

    // Retrieves core part
    PackagePart corePart = demo.getCorePartUri(docPath);
    if (corePart != null)
View Full Code Here

Examples of org.openxml4j.samples.DemoCore

* @version 1.0
*/
public class ListingExtractDocumentExtendedProperties {

  public static void main(String[] args) {
    DemoCore demoCore = new DemoCore();

    // Open the package
    Package p;
    try {
      p = Package.open(demoCore.getTestRootPath() + "sample.docx",
          PackageAccess.READ);

      // Retrieves extended properties part relationship
      PackageRelationship extendedPropertiesRelationship = p
          .getRelationshipsByType(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.