Esempio n. 1
0
  public static void main(String[] args) {
    HashMap configuration = new HashMap();
    configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, OPEN_OFFICE_ORG_PATH);
    configuration.put(
        IOfficeApplication.APPLICATION_TYPE_KEY, IOfficeApplication.LOCAL_APPLICATION);

    try {
      IOfficeApplication officeAplication = OfficeApplicationRuntime.getApplication(configuration);
      officeAplication.activate();
      IDocumentService documentService = officeAplication.getDocumentService();
      IDocument document =
          documentService.constructNewDocument(IDocument.WRITER, DocumentDescriptor.DEFAULT);
      ITextDocument textDocument = (ITextDocument) document;
      textDocument.addCloseListener(new SnippetDocumentCloseListener(officeAplication));

      /*
       * Now do the work with text content.
       */
      placeSomeTextContent(textDocument);

    } catch (OfficeApplicationException exception) {
      exception.printStackTrace();
    } catch (NOAException exception) {
      exception.printStackTrace();
    }
  }
Esempio n. 2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static void starteAusfallRechnung(String url) {
    IDocumentService documentService = null;
    ;
    // System.out.println("Starte Datei -> "+url);
    if (!OpRgaf.officeapplication.isActive()) {
      OpRgaf.starteOfficeApplication();
    }
    try {
      documentService = OpRgaf.officeapplication.getDocumentService();
    } catch (OfficeApplicationException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          null, "Fehler im OpenOffice-System - Ausfallrechnung kann nicht erstellt werden");
      return;
    }
    IDocumentDescriptor docdescript = new DocumentDescriptor();
    docdescript.setHidden(false);
    docdescript.setAsTemplate(true);
    IDocument document = null;
    // ITextTable[] tbl = null;
    try {
      document = documentService.loadDocument(url, docdescript);
    } catch (NOAException e) {

      e.printStackTrace();
    }
    ITextDocument textDocument = (ITextDocument) document;
    ITextFieldService textFieldService = textDocument.getTextFieldService();
    ITextField[] placeholders = null;
    try {
      placeholders = textFieldService.getPlaceholderFields();
    } catch (TextException e) {
      e.printStackTrace();
    }
    for (int i = 0; i < placeholders.length; i++) {
      boolean schonersetzt = false;
      String placeholderDisplayText = placeholders[i].getDisplayText().toLowerCase();
      /** ************** */
      Set<?> entries = InitHashMaps.hmAdrPDaten.entrySet();
      Iterator<?> it = entries.iterator();
      while (it.hasNext()) {
        Map.Entry<String, String> entry = ((Map.Entry<String, String>) it.next());
        if (((String) entry.getKey()).toLowerCase().equals(placeholderDisplayText)) {
          placeholders[i].getTextRange().setText(((String) entry.getValue()));
          schonersetzt = true;
          break;
        }
      }
      /** ************** */
      entries = InitHashMaps.hmAdrAFRDaten.entrySet();
      it = entries.iterator();
      while (it.hasNext() && (!schonersetzt)) {
        Map.Entry entry = (Map.Entry) it.next();
        if (((String) entry.getKey()).toLowerCase().equals(placeholderDisplayText)) {
          placeholders[i].getTextRange().setText(((String) entry.getValue()));
          schonersetzt = true;
          break;
        }
      }
      if (!schonersetzt) {
        OOTools.loescheLeerenPlatzhalter(textDocument, placeholders[i]);
      }
      /** ************** */
    }
  }
Esempio n. 3
0
  /**
   * Now we will write a text to the document. After that is done (we already shoud now how to write
   * text down to the document) we will use a new method to append more text content.
   *
   * @param textDocument the document to place the table in
   * @author Sebastian Rösgen
   * @date 17.03.2006
   */
  public static void placeSomeTextContent(ITextDocument textDocument) {

    textDocument.getTextService().getText().setText("The Raven (excerpt)\n\n");

    String[] text2BePlaced = {
      // since there is no better poem than Edgar Allan Poe's the Raven
      // we will use some staves from it
      "Once upon a midnight dreary, while I pondered weak and weary,",
      "Over many a quaint and curious volume of forgotten lore,",
      "While I nodded, nearly napping, suddenly there came a tapping,",
      "As of some one gently rapping, rapping at my chamber door.",
      "`'Tis some visitor,' I muttered, `tapping at my chamber door -",
      "Only this, and nothing more.'",
      "",
      "...",
      "",
      "Then this ebony bird beguiling my sad fancy into smiling,",
      "By the grave and stern decorum of the countenance it wore,",
      "`Though thy crest be shorn and shaven, thou,' I said, `art sure no craven.",
      "Ghastly grim and ancient raven wandering from the nightly shore -",
      "Tell me what thy lordly name is on the Night's Plutonian shore!'",
      "Quoth the raven, `Nevermore.'",
      "",
      "Much I marvelled this ungainly fowl to hear discourse so plainly,",
      "Though its answer little meaning - little relevancy bore;",
      "For we cannot help agreeing that no living human being",
      "Ever yet was blessed with seeing bird above his chamber door -",
      "Bird or beast above the sculptured bust above his chamber door,",
      "With such name as `Nevermore.'",
      "",
      "...",
      "",
      "But the raven, sitting lonely on the placid bust, spoke only,",
      "That one word, as if his soul in that one word he did outpour.",
      "Nothing further then he uttered - not a feather then he fluttered -",
      "Till I scarcely more than muttered `Other friends have flown before -",
      "On the morrow will he leave me, as my hopes have flown before.'",
      "Then the bird said, `Nevermore.'",
      "",
      "Startled at the stillness broken by reply so aptly spoken,",
      "`Doubtless,' said I, `what it utters is its only stock and store,",
      "Caught from some unhappy master whom unmerciful disaster",
      "Followed fast and followed faster till his songs one burden bore -",
      "Till the dirges of his hope that melancholy burden bore",
      "Of \"Never-nevermore.\"'"
    };

    try {
      ITextCursor textCursor =
          textDocument.getTextService().getText().getTextCursorService().getTextCursor();

      textCursor.gotoEnd(false);

      for (int i = 0; i < text2BePlaced.length; i++) {
        textCursor.getEnd().setText(text2BePlaced[i]); // we place the text
        textCursor.getEnd().setText("\n"); // and we wrap the line
      }
    } catch (TextException exception) {
      exception.printStackTrace();
    }
  }