Macro: ODT in HTML via Kommandozeile

Programmierung unter AOO/LO (StarBasic, Python, Java, ...)

Moderator: Moderatoren

lars-sh
*
Beiträge: 12
Registriert: Di, 24.04.2007 17:58
Wohnort: nahe Hamburg
Kontaktdaten:

Macro: ODT in HTML via Kommandozeile

Beitrag von lars-sh »

Hallo!

ich arbeite für eine OpenSource-Community namens eyeOS (http://eyeos.org/de/). Wir entwickeln ein fortschrittliches Web-Betriebssystem, das zum Öffnen von Office-Dokumenten ein OpenOffice-Macro benutzt. Unter Linux funktioniert dieses ohne Probleme, unter Windows wird die umgewandelte Office-Datei (HTML-Code) jedoch nicht gespeichert. Daher habe ich versucht per "cmd" den Fehler weiter einzugrenzen.

Erklärung: Es exisitiert eine ODT-Datei namens "D:\test.odt". Die Datei "D:\test.html" soll erstellt werden.
Vorgehen:
  • Das Macro (siehe unten!) wird nach "C:\Program Files\OpenOffice.org 2.4\share\basic\Tools\" kopiert.
  • Danach wird in der Datei "C:\Program Files\OpenOffice.org 2.4\share\basic\Tools\script.xlb" eine neue Zeile hinzugefügt: "<library:element library:name="eyeOS"/>" (unter "<library:element library:name="Debug"/>").
  • Als Kommando unter CMD führe ich aus ("C:\Program Files\OpenOffice.org 2.4\program>" bedeutet, dass ich mit "cd" in das Verzeichnis gewechselt bin!):

    Code: Alles auswählen

    C:\Program Files\OpenOffice.org 2.4\program>soffice.exe -headless -norestore "macro:///Tools.eyeOS.ConvertAny(D:\test.odt,D:\test.html,HTML (StarWriter))"
Es wäre schön, wenn wir das Problem beheben könnten!

PS: Vielleicht hilft es ja, wenn ich sage, dass ich Windows Vista verwende, das Problem jedoch auch unter XP (usw.) ist.
PPS: Das Macro (Dateiname: "eyeOS.xba"):

Code: Alles auswählen

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="eyeOS" script:language="StarBasic">
&apos;thanks to DannyB from http://www.oooforum.org/forum/ for this idea and code
&apos;distributed under the terms of GNU Affero General Public License (AGPL) (c) eyeOS 2007-2008
Sub ConvertAny(cFile,newName,myFilter)
On Error Resume Next 
   cURL = ConvertToURL( cFile )
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
            MakePropertyValue( "Hidden", True ),_
            ) )

   cURL = ConvertToURL( newName )
   oDoc.storeToURL( cURL, Array(_
            MakePropertyValue( "FilterName", myFilter ),_
            )
   
   oDoc.close( True )
End Sub

Sub SplitSlides( cImpressDocToSplit, newName )
   On Error Resume Next 
   &apos; Open the document to find out how many pages it has.
   oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array(MakePropertyValue( "Hidden", True )) )
   
   nNumPages = oDoc.getDrawPages().getCount()
   
   &apos; Now that we know how many pages it has, close it.
   oDoc.close( True )
   
   &apos; Now loop once for each page.
   nHighestPageNumber = nNumPages-1
&apos;   nPageToSave = 2
   For nPageToSave = 0 To nHighestPageNumber
   
      &apos; Open the document.
      oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array(MakePropertyValue( "Hidden", True )) )
      
      &apos; Delete all pages except the one we&apos;re interested in keeping
      &apos;  on this loop.
      DeleteAllPagesExcept( oDoc, nPageToSave )

      &apos; Save it as a JPEG.
      oDoc.storeToUrl( ConvertToURL( newName + "_" + nPageToSave + ".png" ), _
         Array( MakePropertyValue( "FilterName", "impress_png_Export" ) ) )
      
      &apos; Close the document without saving it.
      oDoc.close( True )
   Next
   
End Sub

Sub getSingleSlide(cName,myNumber,newName) 
On Error Resume Next 
      oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cName ), "_blank", 0, Array(MakePropertyValue( "Hidden", True )) )
      nNumPages = oDoc.getDrawPages().getCount()
      &apos; Delete all pages except the one we&apos;re interested in keeping
      &apos;  on this loop.
      Dim cNumber as Integer
      cNumber = myNumber
      If cNumber < nNumPages Then
	      DeleteAllPagesExcept( oDoc, cNumber )
	
	      &apos; Save it as a JPEG.
	      oDoc.storeToUrl( ConvertToURL( newName + "_" + myNumber + ".png"  ), _
	         Array( MakePropertyValue( "FilterName", "impress_png_Export" ) ) )
	      
	      &apos; Close the document without saving it.	
      EndIf

      oDoc.close( True )

End Sub

Function DeleteAllPagesExcept( oDoc, nPageToKeep )
On Error Resume Next 
   nNumPages = oDoc.getDrawPages().getCount()
   nHighestPageNumber = nNumPages-1
   
   &apos; Delete the last page, then the page before that,
   &apos;  then the page before that, until we get to the
   &apos;  page to keep.
   &apos; This deletes all pages AFTER the page to keep.
   nPageToDelete = nHighestPageNumber
   Do while nPageToDelete > nPageToKeep
      &apos; Get the page.
      oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
      &apos; Tell the document to remove it.
      oDoc.getDrawPages().remove( oPage )
      
      nPageToDelete = nPageToDelete - 1
   Loop
   
   &apos; Delete all the pages before the page to keep.
   For i = 0 To nPageToKeep - 1
      &apos; Delete the first page.
      nPageToDelete = 0
      &apos; Get the page.
      oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
      &apos; Tell the document to remove it.
      oDoc.getDrawPages().remove( oPage )
   Next
End Function


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
On Error Resume Next 
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function 

</script:module>
Schöne Grüße,
Lars Knickrehm

Das oneye-Projekt. www.oneye-project.org