Forum Discussion

InekeBauw's avatar
InekeBauw
Occasional Contributor
7 years ago
Solved

Add data to excell file with datasink without deleting existing data

I have an excel file that already contains data. I would like to add data to the file, so I use datasink. But the problem is with the datasink that he deletes the existing data in the excel file. C...
  • KirillZakharov's avatar
    7 years ago

    Unfortunately, appending to an Excel file isn't supported. But, we have a corresponding feature request in our DB: "Add possibility to append data to a single Excel file from several DataSinks".

    In the meantime, you can use DataSink of the File type, save the data to a single .csv file (enable the "append to existing file" option for that), and work with the resulting .csv file in Excel.

     

    If it is important for you to use the excel I can offer you the workaround https://www.screencast.com/t/IRe7uYkIrg. You need to add the below Groovy script to the Setup Script for each of your TestCases, and add a new property to TestSuite. Also, please take into account that this script works with a file of Excel type of Microsoft Office 1997-2003.
    Script:
     import jxl.*

      def f = new File("FullPath to .xls file")
      def wk = Workbook.getWorkbook(f)
      s1 = wk.getSheet("SheetID")
      String rows = s1.getRows()+1
      testRunner.testCase.testSuite.setPropertyValue("row", "A"+rows)