Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By sanjeevtarar

Thread: How to open an .odf file in java

  1. #1
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default How to open an .odf file in java

    Hi i Need to open an .odf (calc) file in using java. please help me ::o

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Dear,

    You already have opened a thread with this topic, please do not open duplicate threads, i will provide an example for this after 1 hr.
    sanjeev,संजीव

  3. #3
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    Hi Sanjeev,
    Thanks for your reply.

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Can you more describe about your requirement.

    Do you need a program that reads .odt file and write some text using java

    Do you want to append some text in .odt file?
    sanjeev,संजीव

  5. #5
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    I need to read .odf file and write some of the contents in a text file.
    its like Reading a column from .odf file and print that in a other text file.

    Thankx.

  6. #6
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Run this program by updating the proper path in program, i will also send you the program that will write date in txt file

    Meanwhile you also search OpenOffice form

    Java Code:
    
    import ooo.connector.BootstrapSocketConnector;
    
    import com.sun.star.beans.PropertyValue;
    import com.sun.star.container.XIndexAccess;
    import com.sun.star.container.XNameAccess;
    import com.sun.star.frame.XComponentLoader;
    import com.sun.star.lang.XComponent;
    import com.sun.star.lang.XMultiComponentFactory;
    import com.sun.star.text.XDefaultNumberingProvider;
    import com.sun.star.text.XTextDocument;
    import com.sun.star.text.XTextSection;
    import com.sun.star.text.XTextSectionsSupplier;
    import com.sun.star.uno.UnoRuntime;
    
    public class TestDoc {
    
    	public static void main(String[] args) throws Exception {
    		startProcessing();
    	}
    
    	static void startProcessing() throws Exception {
            String oooExeFolder = "C://Program Files//OpenOffice.org 3//program//";
            com.sun.star.uno.XComponentContext xContext = null;
            try {
                // get the remote office component context
            	xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
                if( xContext != null )
                    System.out.println("Connected to a running office ...");
            }
            catch( Exception e) {
                e.printStackTrace(System.err);
                System.exit(1);
            }
    		
            XMultiComponentFactory xMCF = xContext.getServiceManager();
            Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
            XComponentLoader xCompLoader = (XComponentLoader)
            UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);
            String sUrl = "file:///C:\\Template.odt";
            PropertyValue[] loadProps = new PropertyValue[1];
            loadProps[0] = new PropertyValue();
            loadProps[0].Name = "AsTemplate";
            loadProps[0].Value = new Boolean(true); 
            // Load the document, which will be displayed. More param info in apidoc
            XComponent xComp = xCompLoader.loadComponentFromURL(sUrl, "_blank", 0, loadProps);
            XTextDocument textDocument = (XTextDocument)UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComp);
    	}
    }
    Last edited by sanjeevtarar; 03-17-2011 at 11:54 AM.
    icebreakersandy likes this.
    sanjeev,संजीव

  7. #7
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    Hi Sanjeev,
    Thanks a Lot ...

    :) :)

  8. #8
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    Hi,
    Can i try same code to open .odf File.....

  9. #9
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Yes just try

    If your problem is solved then please mark this as SOLVED
    sanjeev,संजीव

  10. #10
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    Hi Sanjeev,
    i am getting the messege connected to running office.when i am trying for Template.ods instead of Template.odt i am not able to see that file opened....

  11. #11
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    you need to open .odt or .ods
    sanjeev,संजीव

  12. #12
    Join Date
    Mar 2011
    Posts
    52
    Rep Power
    0

    Default

    I need to open .ods File OPen office Calc file and want to read data from cell and write it to text file.

Similar Threads

  1. How to Open .odf(calc) File using java on Click event of button
    By deshmukh.niraj04 in forum New To Java
    Replies: 14
    Last Post: 03-15-2011, 09:31 AM
  2. How to track Save And open a Junit test Java file?
    By jaydip.biswas in forum Eclipse
    Replies: 0
    Last Post: 03-15-2010, 07:44 AM
  3. Replies: 0
    Last Post: 03-05-2010, 05:21 AM
  4. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 03:14 PM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 10:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •