Macro: ODT in HTML via Kommandozeile
Verfasst: Sa, 14.06.2008 15:03
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:
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"):
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))"
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">
'thanks to DannyB from http://www.oooforum.org/forum/ for this idea and code
'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
' 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()
' Now that we know how many pages it has, close it.
oDoc.close( True )
' Now loop once for each page.
nHighestPageNumber = nNumPages-1
' nPageToSave = 2
For nPageToSave = 0 To nHighestPageNumber
' Open the document.
oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array(MakePropertyValue( "Hidden", True )) )
' Delete all pages except the one we're interested in keeping
' on this loop.
DeleteAllPagesExcept( oDoc, nPageToSave )
' Save it as a JPEG.
oDoc.storeToUrl( ConvertToURL( newName + "_" + nPageToSave + ".png" ), _
Array( MakePropertyValue( "FilterName", "impress_png_Export" ) ) )
' 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()
' Delete all pages except the one we're interested in keeping
' on this loop.
Dim cNumber as Integer
cNumber = myNumber
If cNumber < nNumPages Then
DeleteAllPagesExcept( oDoc, cNumber )
' Save it as a JPEG.
oDoc.storeToUrl( ConvertToURL( newName + "_" + myNumber + ".png" ), _
Array( MakePropertyValue( "FilterName", "impress_png_Export" ) ) )
' 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
' Delete the last page, then the page before that,
' then the page before that, until we get to the
' page to keep.
' This deletes all pages AFTER the page to keep.
nPageToDelete = nHighestPageNumber
Do while nPageToDelete > nPageToKeep
' Get the page.
oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
' Tell the document to remove it.
oDoc.getDrawPages().remove( oPage )
nPageToDelete = nPageToDelete - 1
Loop
' Delete all the pages before the page to keep.
For i = 0 To nPageToKeep - 1
' Delete the first page.
nPageToDelete = 0
' Get the page.
oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
' 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>