Beispiel #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();
    }
  }
Beispiel #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]);
      }
      /** ************** */
    }
  }