OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Danny's Document Converter

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
verson
General User
General User


Joined: 18 Feb 2005
Posts: 7
Location: Australia

PostPosted: Fri Feb 18, 2005 1:52 pm    Post subject: Danny's Document Converter Reply with quote

I need to convert a large number of files from sxc to sdc, and I found Danny's Document Converter. I"m not a programmer, so am unable to alter the code to do this
Can anyone tell me how to add this feature to ther document converter?
It can be downloaded from

http://prdownloads.sourceforge.net/ooomacros/DocConverter_2003-10-26.zip?download
or goto http://www.ooomacros.org/user.php

Thanks
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Feb 19, 2005 11:32 am    Post subject: Reply with quote

Want to convert a folder full of one type of document into another type.

I started with this example.
http://www.oooforum.org/forum/viewtopic.phtml?p=45659#45659
This converts a folder full of HTML files. Each HTML file is imported into Writer, and then saved as SXW,DOC,PDF,TXT.

I just modified the example so that it no longer uses an import filter. (The filter was to convert incomming HTML into Writer. We're just opening raw Calc files.)

Then I modified the output code to only export to SDC (StarCalc 5.0).

This is a quick and dirty hack. I found it faster than trying to adapt the DocumentConverter.

Code:
Sub Main
   '----------
   ' CHANGE ME !!!
   ' Pathname must be that of a FOLDER not a FILE.
   '
   cSourceFolder = "C:\Documents and Settings\dbrewer\Desktop\Test"
   '
   '----------
   

   ' Convert from pathname into a URL.
   cSourceFolderUrl = ConvertToUrl( cSourceFolder )

   oSimpleFileAccess = createUnoService( "com.sun.star.ucb.SimpleFileAccess" )
   If Not oSimpleFileAccess.isFolder( cSourceFolderUrl ) Then
      MsgBox( "You must specify a folder to convert, not a file." )
      Exit Sub
   EndIf
   
   ' Convert a folder full of HTML into PDF.
   ' All sub-folders are also processed, so beware of passing
   '  the root of your hard drive, as all HTML files on your entire
   '  drive would be processed.
   DoFolder( oSimpleFileAccess, cSourceFolderUrl )
End Sub



Sub DoFolder( oSimpleFileAccess, cFolderUrl )
   
   ' Get an array of the names of items in this folder.
   aFolderItems = oSimpleFileAccess.getFolderContents( cFolderUrl, True )
   
   ' Now iterate over each item in this folder.
   For i = LBound( aFolderItems ) To UBound( aFolderItems )
      ' Get the name of an item in this cFolderUrl.
      cFolderItemUrl = aFolderItems( i )
     
      ' Is this item a sub folder?
      If oSimpleFileAccess.isFolder( cFolderItemUrl ) Then
         ' Process a sub-folder
         DoFolder( oSimpleFileAccess, cFolderItemUrl )
      Else
         ' Process a file.
         DoAFile( cFolderItemUrl )
      EndIf
   Next
End Sub




Sub DoAFile( cSourceDocUrl )

   ' Open Html as a Writer document
   ' The Hidden property causes the document window to be invisible
   '  so that you don't see a bunch of windows suddenly pop up and then disappear.
   ' If you open the documents invisible then BE SURE to close them again!
   ' (See below for the close step.)  Otherwise, you end up with a bunch of
   '  open documents, but they are invisible and the user is unable to close
   '  the invisible windows!
   oDoc = StarDesktop.loadComponentFromURL( cSourceDocUrl, "_blank", 0,_
         Array( MakePropertyValue( "Hidden", True ) ) )


   ' Save as SDC (i.e. StarCalc 5.0)
   ' Same as cSourceDoc, but different extension
   cDestDoc = Left( cSourceDocUrl, Len( cSourceDocUrl ) - 4 ) + ".sdc"

   oDoc.storeToURL( cDestDoc,_
         Array( MakePropertyValue( "FilterName", "StarCalc 5.0" ) ) )
   
   
   ' Close the document
   ' If you don't do this, then you end up with a whole bunch of open
   '  documents in the office.
   oDoc.close( True )
End Sub


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "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

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
verson
General User
General User


Joined: 18 Feb 2005
Posts: 7
Location: Australia

PostPosted: Wed Feb 23, 2005 2:29 pm    Post subject: Document conversion Reply with quote

Thanks for the reply.
However, I wanted to convert all my sxc files back to sdc (because of formatting issues).
Is there any way to do this easily ?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Feb 26, 2005 10:34 am    Post subject: Re: Document conversion Reply with quote

verson wrote:
Thanks for the reply.
However, I wanted to convert all my sxc files back to sdc (because of formatting issues).
Is there any way to do this easily ?


Maybe I'm not clear on what you wanted? The above example converts a folder (and all sub-folders) of SXC documents into SDC. Be sure that the folder ONLY has SXC files when you start the macro.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group