Forum Discussion

superuser's avatar
superuser
Occasional Contributor
14 years ago

Open Office support

Hi



Is test complete ver. 7  support the open office? We are struck as previously we are working on MS Office and now have to move on Open office..

Please suggest!!

Thanks in Advance

Satish

2 Replies


  • Hi Satish,





    OpenOffice applications don't expose GUI objects (the interface seems to be just drawn on their windows), and there's no way to work with them via COM, therefore, you cannot work with them from script in the way you would do this with MS Office applications. However, if you describe your task in detail, we can try to find a workaround for you. For example, if you want to save some data to an OpenOffice spreadsheet, I can suggest the following solution - save the data to a CSV file, launch OpenOffice Calc and convert the file to the needed format.
  • Hi,


    It is possible to work with Open Office API


    After getting its two objects "com.sun.star.ServiceManager", and "com.sun.star.frame.Desktop" you can do almost anything with it.


    Here's an example on how to write some data to Open Office Calc and save the document (JScript):


    FileName  - full path for the new file



    function SaveSmthToCalc(FileName)

    {

    try

    {

    //creating Desktop object

    var oServiceManager = Sys.OleObject("com.sun.star.ServiceManager");

    var oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop");



    // creating an array of document parameters

    // and placing there a value Hidden=true, so that Open office calc won't be shown

    var VariantArray = new Array();

    var Mystruct = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue");

    Mystruct.Name = "Hidden";

    Mystruct.Value = true;

    VariantArray[0] = Mystruct;



    //creating a document

    //first parameter can be a URL path to an existing document (then existing document will be changed)

    var oDoc = oDesktop.LoadComponentFromURL("private:factory/scalc", "_blank", 0, VariantArray);

    //getting first sheet

    var oSheet = oDoc["getSheets"]().getByIndex(0);



      //filling several with some values

    for (var j=0; j<10; j++)

    for(var i=0; i<10; i++)

    oSheet.getCellByPosition(i, j).setString("Col:"+i+" Row:"+j);



    //saving the document

    // url path should be used here, so converting usual path to it

    oDoc.storeAsURL("file:///"+aqString.Replace(FileName, "\\", "/"), VariantArray);

    //closing document

    oDoc.Close(false);

    }

    catch(exception)

    {

    Log.Warning("Unable to save the data to ods table", exception.description);

    }



    }