Seite 1 von 1

oO Writer Dokument per Java/PHP erstellen

Verfasst: Fr, 03.02.2006 09:21
von rudL
hi!
der ursprüngliche gedanke war ein oO Writer dokument per PHP zu generieren - allerdings schätz ich mal wird das problematischer bzw. unmöglich werden, nachdem was ich bis jetzt gelesen hab...

meine frage ist wie ich das ganze dann mit java umsetzen kann? und wenn wer ein paar brauchbare unterlagen (dokus, beispiele) kennt pls posten.

bin diesbezüglich leider ein newbie und seh vor lauter bäumen den wald nicht :(

thx im vorhinein

Verfasst: Fr, 03.02.2006 11:54
von pmoegenb
Möglicher Weise findest Du unter http://de.openoffice.org/doc/faq/api/index.html das Passende.

Gruß

Peter

Re: oO Writer Dokument per Java/PHP erstellen

Verfasst: Fr, 03.02.2006 19:50
von hol.sten
rudL hat geschrieben:der ursprüngliche gedanke war ein oO Writer dokument per PHP zu generieren
Hier findest du zumindest mal ein Beispiel, wie man aus PHP OOo aufruft: http://www.oooforum.org/forum/viewtopic ... hlight=php
rudL hat geschrieben:brauchbare unterlagen (dokus, beispiele)
Die umfangreiste Doku zur OOo API ist immer noch der OOo Developer's Guide http://api.openoffice.org/DevelopersGui ... Guide.html. Voll mit Java-Beispielen.

With kind regards
hol.sten

Verfasst: Do, 23.02.2006 13:01
von rudL
thx 4 die links, hab ma mal alles genau angeschaut allerdings steh ich momentan gerade an und weis nicht weiter :(

hab mal per php folgendes versucht:
1) datei context.xml erstellen
2) inhalt einfügen
3) xml dateien unkomprimiert packen
4) in odt bzw sxw format speichern

Code: Alles auswählen

$filename = "content.xml";
$content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE office:document-content PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"office.dtd\"><office:document-content xmlns:office=\"http://openoffice.org/2000/office\" xmlns:style=\"http://openoffice.org/2000/style\" xmlns:text=\"http://openoffice.org/2000/text\" xmlns:table=\"http://openoffice.org/2000/table\" xmlns:draw=\"http://openoffice.org/2000/drawing\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:number=\"http://openoffice.org/2000/datastyle\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:chart=\"http://openoffice.org/2000/chart\" xmlns:dr3d=\"http://openoffice.org/2000/dr3d\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"http://openoffice.org/2000/form\" xmlns:script=\"http://openoffice.org/2000/script\" office:class=\"text\" office:version=\"1.0\"><office:script/><office:font-decls><style:font-decl style:name=\"Tahoma1\" fo:font-family=\"Tahoma\"/><style:font-decl style:name=\"Arial Unicode MS\" fo:font-family=\"&apos;Arial Unicode MS&apos;\" style:font-pitch=\"variable\"/><style:font-decl style:name=\"Tahoma\" fo:font-family=\"Tahoma\" style:font-pitch=\"variable\"/><style:font-decl style:name=\"Times New Roman\" fo:font-family=\"&apos;Times New Roman&apos;\" style:font-family-generic=\"roman\" style:font-pitch=\"variable\"/></office:font-decls><office:automatic-styles><style:style style:name=\"P1\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"><style:properties fo:font-size=\"14pt\" style:font-size-asian=\"14pt\" style:font-size-complex=\"14pt\"/></style:style><style:style style:name=\"P2\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"><style:properties fo:font-size=\"14pt\" fo:font-weight=\"bold\" style:font-size-asian=\"14pt\" style:font-weight-asian=\"bold\" style:font-size-complex=\"14pt\" style:font-weight-complex=\"bold\"/></style:style><style:style style:name=\"P3\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"><style:properties fo:font-size=\"15pt\" fo:font-weight=\"bold\" style:font-size-asian=\"15pt\" style:font-weight-asian=\"bold\" style:font-size-complex=\"15pt\" style:font-weight-complex=\"bold\"/></style:style><style:style style:name=\"P4\" style:family=\"paragraph\" style:parent-style-name=\"Standard\"><style:properties fo:font-size=\"15pt\" style:font-size-asian=\"15pt\" style:font-size-complex=\"15pt\"/></style:style></office:automatic-styles><office:body><text:sequence-decls><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Illustration\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\"/></text:sequence-decls><text:p text:style-name=\"Standard\">Tadaa</text:p><text:p text:style-name=\"P1\">Tadaa</text:p><text:p text:style-name=\"P2\">Tadaa</text:p><text:p text:style-name=\"P3\"/><text:p text:style-name=\"P3\">Tadaa</text:p><text:p text:style-name=\"P4\"/></office:body></office:document-content>";

if (file_exists($filename))
  unlink($filename);

$dataFile = fopen($filename, "a" ) ;
if ($dataFile)
{
  while (!feof($dataFile))
  {
     $buffer = fgets($dataFile, 4096);
     echo $buffer;
  }
  fclose($dataFile);
}
else
{
  die( "fopen failed for $filename" ) ;
}


  //  check file
  if (is_writable($filename))
  {
    if (!$handle = fopen($filename, "a"))
    {
      echo "error: file $filename corrupted<br>";
      exit;
    }
    
    //    write data to file
    if (!fwrite($handle, $content))
    {
       echo "error: unable to edit $filename<br>";
       exit;
    }
    fclose($handle);
  }
  else
    echo "error: unable to edit $filename<br>";


  
//zip files
ob_start();
require('zip.lib.php');

$zipfile = new zipfile('oo.sxw');
$zipfile->addFileAndRead('content.xml');
$zipfile->addFileAndRead('meta-inf/manifest.xml');
$zipfile->addFileAndRead('meta.xml');
$zipfile->addFileAndRead('mimetype');
$zipfile->addFileAndRead('settings.xml');
$zipfile->addFileAndRead('styles.xml');

echo $zipfile->file();
funktioniert theoretisch - praktisch streikt OOo wenn ich nicht die original datei verwende (content.xml) obwohl sich in der erzeugten kopie davon der identische inhalt befindet.

btw: hab die folgenden files zum zippen verwendet
http://www.php-resource.de/forum/attach ... tid=357551

hab dann das ganze auf eine andere variante probiert:

Code: Alles auswählen

$oArgs = array();
$objServiceManager = new COM( "com.sun.star.ServiceManager" );
$Stardesktop = $objServiceManager->createInstance( "com.sun.star.frame.Desktop" );
$doc = $Stardesktop->loadComponentFromURL("private:factory/swriter", "_blank", 0, $oArgs );
$text = $doc->getText();
$text->setString("Hello World"); 
hier bekomme ich allerdings die meldung:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `com.sun.star.ServiceManager': Ungültige Syntax ' in C:\Programme\xampp\htdocs\rudL\test\oO2\oo.php:4 Stack trace: #0 C:\Programme\xampp\htdocs\rudL\test\oO2\oo.php(4): com->com('com.sun.star.Se...') #1 {main} thrown in C:\Programme\xampp\htdocs\rudL\test\oO2\oo.php on line 4
habe OpenOffice.org1.1.2 installiert (die ver OpenOffice.org 2.0 ist inzwischen wieder herunten)
OpenOffice.org1.1_SDK
jre1.5.0_06
und php 5

kenn mi inzwischen scho überhaupt nix mehr aus und weiß net was i jetzt für die 2te variante alles installiert haben soll und wo ich was downloaden kann *confused*

thx im voraus,
rudL

Verfasst: Sa, 25.02.2006 11:54
von hol.sten
rudL hat geschrieben:funktioniert theoretisch - praktisch streikt OOo wenn ich nicht die original datei verwende (content.xml) obwohl sich in der erzeugten kopie davon der identische inhalt befindet.
Wenn du die Original-OOo-Datei und die selbst zusammengesetzte OOo-Datei zum Download anbieten würdest, könnte ich mal reinschauen. Vielleicht fällt mir dann was ein.
rudL hat geschrieben:hab dann das ganze auf eine andere variante probiert:...

hier bekomme ich allerdings die meldung:
...'Failed to create COM object `com.sun.star.ServiceManager':...
Läuft für diese Variante eine OOo 1.1.x Instanz im Listen Modus? Wenn du nun gar nicht weißt, was ich damit meine, schau mal im OOo 1.1 SDK in den OOo Developers Guide "2.3 Getting Started - Make the office listen".
rudL hat geschrieben:habe OpenOffice.org1.1.2 installiert (die ver OpenOffice.org 2.0 ist inzwischen wieder herunten)
Warum?

With kind regards
hol.sten