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

HOW TO CONVERT .SWX FILE TO .DOC

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
MINTXELA
Newbie
Newbie


Joined: 21 Sep 2005
Posts: 2

PostPosted: Wed Sep 21, 2005 12:49 am    Post subject: HOW TO CONVERT .SWX FILE TO .DOC Reply with quote

HELLO ALL.

YESTERDAY I WAS HAVING A LOOK ON THIS SITE, LOOKING FOR ANY SOURCE FOR CONVERTING A .SWX TO .DOC AND I FOUND THE SOURCE THAT FOLLOWS...
THIS PIECE OF SOURCE WORKS FINE, BUT, I WOULD LIKE TO MAKE THE CONVERSION WITHOUT OPENING THE DOCUMENT. iF THERE IS NO WAY FOR THAT, ANY INFORMATION OR LINK ABOUT CLOSING ONE DOCUMENT WOULD BE ENOUGH.

THANKS IN ADVANCE.
MINTXELA.


//-----------------------------------------------------------------------------------------------------

package openoffice;

import com.sun.star.awt.FontWeight;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import com.sun.star.awt.Point;
import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyState;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertyState;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.servicemanager.ServiceManager;
import com.sun.star.connection.XConnection;
import com.sun.star.connection.XConnector;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XIndexReplace;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNamed;
import com.sun.star.drawing.XDrawPageSupplier;
import com.sun.star.drawing.XShape;
import com.sun.star.drawing.XShapeGrouper;
import com.sun.star.drawing.XShapes;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.style.NumberingType;
import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.table.XCell;
import com.sun.star.text.ControlCharacter;
import com.sun.star.text.ReferenceFieldPart;
import com.sun.star.text.ReferenceFieldSource;
import com.sun.star.text.TextColumn;
import com.sun.star.text.TextContentAnchorType;
import com.sun.star.text.XAutoTextContainer;
import com.sun.star.text.XAutoTextEntry;
import com.sun.star.text.XAutoTextGroup;
import com.sun.star.text.XBookmarksSupplier;
import com.sun.star.text.XDependentTextField;
import com.sun.star.text.XDocumentIndex;
import com.sun.star.text.XFootnote;
import com.sun.star.text.XFootnotesSupplier;
import com.sun.star.text.XPageCursor;
import com.sun.star.text.XParagraphCursor;
import com.sun.star.text.XReferenceMarksSupplier;
import com.sun.star.text.XRelativeTextContentInsert;
import com.sun.star.text.XSentenceCursor;
import com.sun.star.text.XSimpleText;
import com.sun.star.text.XText;
import com.sun.star.text.XTextColumns;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextField;
import com.sun.star.text.XTextFieldsSupplier;
import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextSection;
import com.sun.star.text.XTextTable;
import com.sun.star.text.XTextTableCursor;
import com.sun.star.text.XTextTablesSupplier;
import com.sun.star.text.XTextViewCursor;
import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.text.XWordCursor;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.XInterface;
import com.sun.star.uno.XNamingService;
import com.sun.star.util.XRefreshable;
import com.sun.star.view.XPrintable;

import java.lang.Math;

import java.util.Hashtable;
import java.util.Random;


public class SXWtoDOC
{
private static String sOutputDir;
private XComponentContext mxRemoteContext = null;
private XMultiComponentFactory mxRemoteServiceManager = null;
private XTextDocument mxDoc = null;
private XMultiServiceFactory mxDocFactory = null;
private XMultiServiceFactory mxFactory = null;
private XPropertySet mxDocProps = null;
private XText mxDocText = null;
private XTextCursor mxDocCursor = null;
private XTextContent mxFishSection = null;
private Random maRandom = null;

//private String unoUrl = "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager";
private String unoUrl = "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";


public SXWtoDOC()
{
try
{
System.out.println("Pretvorba.. sxw v doc");
System.out.println("uno url: " + unoUrl);
mxRemoteServiceManager = this.getRemoteServiceManager(unoUrl);

// retrieve the Desktop object, we need its XComponentLoader
Object desktop = mxRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
mxRemoteContext);
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
desktop);
PropertyValue[] loadProps = new PropertyValue[0];

java.io.File sourceFile = new java.io.File("c:/peter.sxw");
StringBuffer sLoadFileUrl = new StringBuffer("file:///");
sLoadFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));

XComponent xDoc = xComponentLoader.loadComponentFromURL(sLoadFileUrl.toString(),
"_blank", 0, loadProps);

if (xDoc != null)
{
String sOutputDir ="c:/";
sourceFile = new java.io.File(sOutputDir);

StringBuffer sStoreFileUrl = new StringBuffer();
sStoreFileUrl.append(sourceFile.toURL().toString());
sStoreFileUrl.append("somepopularfileformat.doc");
storeDocComponent(xDoc, sStoreFileUrl.toString());

//printDocComponent(xDoc);
}
}
catch (Exception exc)
{
System.out.println("Napaka: " + exc.toString());
}
}

private XMultiComponentFactory getRemoteServiceManager(String unoUrl)
throws java.lang.Exception
{
if (mxRemoteContext == null)
{
XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);

XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();

Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
xLocalContext);

// query XUnoUrlResolver interface from urlResolver object
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class,
urlResolver);

// Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
// retrieve its property DefaultContext and get the remote servicemanager
Object initialObject = xUnoUrlResolver.resolve(unoUrl);
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
initialObject);
Object context = xPropertySet.getPropertyValue("DefaultContext");
mxRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class,
context);
}

return mxRemoteContext.getServiceManager();
}

protected void storeDocComponent(XComponent xDoc, String storeUrl)
throws java.lang.Exception
{
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class,
xDoc);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "MS Word 97";

xStorable.storeAsURL(storeUrl, storeProps);
}

public static void main(String[] args)
{
SXWtoDOC SXWtoDOC1 = new SXWtoDOC();
}
}
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3267
Location: Hamburg, Germany

PostPosted: Wed Sep 21, 2005 2:32 am    Post subject: Re: HOW TO CONVERT .SWX FILE TO .DOC Reply with quote

MINTXELA wrote:
THIS PIECE OF SOURCE WORKS FINE, BUT, I WOULD LIKE TO MAKE THE CONVERSION WITHOUT OPENING THE DOCUMENT.

That is not possible.

MINTXELA wrote:
iF THERE IS NO WAY FOR THAT, ANY INFORMATION OR LINK ABOUT CLOSING ONE DOCUMENT WOULD BE ENOUGH.

Try something like this:
Code:
  try
   {
     // use close(boolean DeliverOwnership)
     // The boolean parameter DeliverOwnership tells objects vetoing the close process that they may
     // assume ownership if they object the closure by throwing a CloseVetoException
     // Here we give up ownership. To be on the safe side, catch possible veto exception anyway.
     xCloseable.close(true);
   }
   catch(com.sun.star.util.CloseVetoException exCloseVeto)
   {
   }

Read more about closing and how to obtain xClosable in the OOo Developer's Guide at http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.htm#1+1+5+Handling+Documents

With kind regards
hol.sten
Back to top
View user's profile Send private message
MINTXELA
Newbie
Newbie


Joined: 21 Sep 2005
Posts: 2

PostPosted: Wed Sep 21, 2005 2:34 am    Post subject: Reply with quote

Thanks a lot for your help.
Back to top
View user's profile Send private message
n0mer
General User
General User


Joined: 20 Mar 2006
Posts: 46

PostPosted: Tue Jun 27, 2006 6:19 am    Post subject: Re: HOW TO CONVERT .SWX FILE TO .DOC Reply with quote

hol.sten wrote:
MINTXELA wrote:
THIS PIECE OF SOURCE WORKS FINE, BUT, I WOULD LIKE TO MAKE THE CONVERSION WITHOUT OPENING THE DOCUMENT.

That is not possible.


Maybe this is about loading document in hidden mode?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer 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