Seite 1 von 1

Wie speichere ich eine Datei?

Verfasst: Fr, 15.04.2011 21:02
von Jonny1
Um JPG-Bilder aufzulisten habe ich folgende Routine geschrieben:

Code: Alles auswählen

Sub ExampleDir3g
	oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
	oText = oDoc.getText()
	oCursor = oText.createTextCursor()

	Dim sFileName As String
	Dim sPath
	sPath = "C:\Dieses Verzeichnis\"
	StringA = "JPG-Bilder in """ + sPath + """<BR><BR>" + CHR$(13)
	oText.insertString( oCursor, StringA, False )
	sFileName = Dir(sPath + "*.jpg")
	Do While (sFileName <> "")
		StringA = sFileName + "<BR>" + CHR$(13) + "<IMG SRC=""" + sPath + sFileName + """ WIDTH=50%> <BR> <BR>" + CHR$(13)
		oText.insertString( oCursor, StringA, False )
		sFileName = Dir()
	Loop
	   
End Sub
Jetzt möchte ich das Dokument oDoc speichern. Wie geht es?

Danke

Re: Wie speichere ich eine Datei?

Verfasst: Fr, 15.04.2011 23:31
von Jonny1
Die Prozedur habe ich so geändert::

Code: Alles auswählen

Sub ExampleDir3
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
   oText = oDoc.getText()
   oCursor = oText.createTextCursor()

   Dim sFileName As String
   Dim sPath
   sPath = "C:\2011-01-13-1349-02\"
   StringA = "JPG-Bilder in """ + sPath + """<BR><BR>" + CHR$(13)
   oText.insertString( oCursor, StringA, False )
   sFileName = Dir(sPath + "*.jpg")
   Do While (sFileName <> "")
      StringA = sFileName + "<BR>" + CHR$(13) + "<IMG SRC=""" + sPath + sFileName + """ WIDTH=50%> <BR> <BR>" + CHR$(13)
      oText.insertString( oCursor, StringA, False )
      sFileName = Dir()
   Loop
   
	rem ----------------------------------------------------------------------
	rem define variables
'	dim document   as object
	dim dispatcher as object
	rem ----------------------------------------------------------------------
	rem get access to the document
'	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	
	rem ----------------------------------------------------------------------
	dim args1(1) as new com.sun.star.beans.PropertyValue
	args1(0).Name = "URL"
	args1(0).Value = "file:///C:/2011-01-13-1349-02/Verzeichnis mit OO-Basic A5.txt"
	args1(1).Name = "FilterName"
	args1(1).Value = "writer8"
	
	dispatcher.executeDispatch(oDoc.CurrentController.Frame, ".uno:SaveAs", "", 0, args1())
	

End Sub
Es funktioniert auch. Der Dateityp ist aber nicht txt, sondern odt, trotz der Erweiterung ".txt". Hängt das vom Parameter "writer8" ab? Wie kann ich es ändern?

Danke

Re: Wie speichere ich eine Datei?

Verfasst: Fr, 15.04.2011 23:48
von Karolus
Hallo
Den Teil zur Speicherung hast du doch aus einer Makroaufzeichnung - was könnte man bei der Makroaufzeichnung tun damit ins gewünschte Format gespeichert wird ? :!: ...Richtig, man wählt das gewünschte Format aus.

Gruß Karo

Re: Wie speichere ich eine Datei?

Verfasst: Sa, 16.04.2011 00:15
von Jonny1
Es funktioniert:

Code: Alles auswählen

Sub ExampleDir3
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
   oText = oDoc.getText()
   oCursor = oText.createTextCursor()

   Dim sFileName As String
   Dim sPath
   sPath = "C:\2011-01-13-1349-02\"
   StringA = "JPG-Bilder in """ + sPath + """<BR><BR>" + CHR$(13)
   oText.insertString( oCursor, StringA, False )
   sFileName = Dir(sPath + "*.jpg")
   Do While (sFileName <> "")
      StringA = sFileName + "<BR>" + CHR$(13) + "<IMG SRC=""" + sPath + sFileName + """ WIDTH=50%> <BR> <BR>" + CHR$(13)
      oText.insertString( oCursor, StringA, False )
      sFileName = Dir()
   Loop
   
   rem ----------------------------------------------------------------------
   rem define variables
'   dim document   as object
   dim dispatcher as object
   rem ----------------------------------------------------------------------
   rem get access to the document
'   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
   
   rem ----------------------------------------------------------------------
   dim args1(1) as new com.sun.star.beans.PropertyValue
   args1(0).Name = "URL"
   args1(0).Value = "file:///C:/2011-01-13-1349-02/Verzeichnis mit OO-Basic A5.html"
   args1(1).Name = "FilterName"
   args1(1).Value = "Text"
   
   dispatcher.executeDispatch(oDoc.CurrentController.Frame, ".uno:SaveAs", "", 0, args1())
   

End Sub