Forum Discussion

Morgan's avatar
Morgan
Frequent Contributor
12 years ago
Solved

Open Office

I am trying to open Open Office, click a specified tab in a specific document and copy all data on that tab.  In Excel, this seems to work great but I am having difficulty getting this to work in Open Office (or I'm just not thinking clearly today).  Any ideas?  



Working Excel script looks like...




  bk := AppPath +'Resources\Table.xls';


  


  Excel := Sys.OleObject('Excel.Application');


  


  Excel.Visible := True;                        


  


  While not Excel.Visible = true


        do delay (500, 'Waiting for Excel to open');

 


  Excel.Workbooks.Open (bk);   

6 Replies

  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Morgan,



    Actually, conversion from VBScript is easier than to VBScript because you should not bother whether or not use the Set keyword.

    For the link that you mentioned I got this (untested, just converted while writing this reply):



    procedure main();

      var ServiceManager : OleVariant;

      var Desktop : OleVariant;

      var Document : OleVariant;

      var Sheets : OleVariant;

      var Sheet : OleVariant;

      var SaveParam : OleVariant;

      var i, j : integer;

      var arr : OleVariant;

    begin

      ServiceManager := Sys.OleObject('com.sun.star.ServiceManager');

      Desktop := ServiceManager.createInstance('com.sun.star.frame.Desktop');

      // arr = Array()

      arr := BuiltIn.CreateVariantArray(0, -1);

      Document := Desktop.LoadComponentFromURL('private:factory/scalc', '_blank', 0, arr);

      Sheets := Document.getSheets();

      Sheet := Sheets.getByIndex(0);

      Sheet.getCellByPosition(0, 0).SetFormula('My Table Title');

      for i := 0 to 9 do

      begin

        Sheet.getCellByPosition(i, 1).SetFormula(aqString.Format('Column %i', i+1));

        for j := 0 to 9 do

          Sheet.getCellByPosition(i, j+2).Value := i + j;

      end;

      SaveParam := ServiceManager.Bridge_GetStruct('com.sun.star.beans.PropertyValue');

      SaveParam.Name := 'FilterName';

      SaveParam.Value := 'MS Excel 97';

      arr := BuiltIn.CreateVariantArray(0, 0);

      arr[0] := SaveParam;

      Document.storeToURL('file:///c:/test.xls', arr);

    end;





    Hope, this will help...



    P.S. I failed to make correct formatting, so please replace [ ] with a space and ['] with a single quote
  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Morgan,



    Great. Thank you for the update.

    Conversion was done manually. Actually, especially if the author of the original code did not use language-specific functions and features but tried to use TestComplete's functions that do the same (I mentioned this in the "Namemapping nightmare" thread), the conversion is quite straightforward: delete all Set keywords; add semicolon at the end of every line; replace all = with := (considering conditions in the if/while/etc.); replace all double-quotes with the single ones and double single quotes inside strings; enclose procedure/function bodies within the begin/end block; etc.

    There is no function in TestComplete that does the conversion, but after converting code to and from several times one usually has no problems with manual conversion.
  • Morgan's avatar
    Morgan
    Frequent Contributor
    Thanks, Alexei - From that link I was able to find the following with an example which is proving to do what I want to in VBScript..

    http://support.smartbear.com/viewarticle/54653/



    I am having difficulty getting the example script converted to DelphiScript but I can muck with it more and see if I can get it.



    Thank you!

    Morgan
  • Morgan's avatar
    Morgan
    Frequent Contributor
    OH HAPPY DAY!!!  It works!!!!  Dumb question for you....  did you manually convert that or is there some function with TC that I am unaware of that will do it for me?  I am on an older version currently, if it matters.  Thank you SO much!
  • Morgan's avatar
    Morgan
    Frequent Contributor
    Thanks, Alexei - you've been very helpful!  Have a good day!