cancel
Showing results for 
Search instead for 
Did you mean: 

Add data to excell file with datasink without deleting existing data

SOLVED
Highlighted
Occasional Contributor

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.

Can this be bypassed?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Add data to excell file with datasink without deleting existing data

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)


Kirill Zakharov
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

2 REPLIES 2

Re: Add data to excell file with datasink without deleting existing data

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)


Kirill Zakharov
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

Jey
New Member

Re: Add data to excell file with datasink without deleting existing data

In datasink test step,  Did you select the checkbox for'Append to end of file'?

 

 

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors