Forum Discussion

dhirendranaga's avatar
dhirendranaga
Occasional Contributor
9 years ago

Copied some content to Sys.clipboard, how to copy this to new excel sheet

Hi,

 

We are using Python as project scripting language.

Have copied content from application using Sys.Keys('^c') and Sys.Keys('^a')

Now, requirement is to create a new excel sheet and copy this content in first row and first column.

 

Please suggest.

 

Regards

Dhirendra.

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    Hi dhirendranaga,

    There are several ways to do this.

    Two examples would be to create an ADO connection to the excel sheet and insert a record, or use TestComplete to paste the data into the first column. To access the clipboard contents use Sys.Clipboard.

    • dhirendranaga's avatar
      dhirendranaga
      Occasional Contributor

      Hi,

       

      Can you please provide some sample code as how to paste code from Sys.ClipBoard to excel first sheet first cell.

       

      Would be of great help please.

       

      Dhirendra.

      • altemann's avatar
        altemann
        Contributor

        Hey dhirendranaga!

        This should work:

         

        function InsertTextExcel()
        {
          var excel = Sys.OleObject("Excel.Application"); excel.DisplayAlerts = false; //No messages
          var book = app.Workbooks.Open("C:\\TC\\ArquivoEXCEL"); //Path to your excel file
          var sheet = book.Sheets("Plan1"); //Name of the sheet
        
          sheet.Cells(1, 1) = Sys.Clipboard;
            
          book.Save();
          app.Quit();
        }