By Aditya Kumar


2018-06-13 14:06:33 8 Comments

I am trying to write the data in excel or CSV file using beanshell. But i am able to write the data in excel sheet but unable to write the data at particular cell in CSV file.

Below is the code.

var response = prev.getResponseDataAsString(); 
f = new FileOutputStream("C:/Users/adityak/Desktop/K/app.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(response);
f.close();

Any help would be appreciated.

1 comments

@Dmitri T 2018-06-13 14:40:38

  1. CSV file doesn't have "cells", it is plain text file with delimiters, mostly commas as CSV stands for comma-separated values
  2. Since JMeter 3.1 it is recommended to use Groovy for scripting
  3. Assuming all above:

For example if you have file like:

1,2,3
4,5,6
7,8,9

and want to replace 5 with hello the relevant Groovy code would be something like:

def csvFile = new File('/home/dtikhanski/Desktop/test.csv')
def lines = csvFile.readLines()


def secondLine = lines.get(1)
def entries = secondLine.split(",")
entries[1] = 'hello'
secondLine = entries.join(',')
lines.set(1, secondLine)

csvFile.withWriter{ out ->
    lines.each {out.println it}
}

Demo:

JMeter Groovy Replace CSV

@Aditya Kumar 2018-06-15 14:45:13

Thanks. It worked for me.

Related Questions

Sponsored Content

2 Answered Questions

How to extract response data JSON and save variable to CSV file in Jmeter

  • 2018-08-01 10:07:38
  • Palash Jain
  • 257 View
  • 2 Score
  • 2 Answer
  • Tags:   jmeter

2 Answered Questions

2 Answered Questions

[SOLVED] JMeter, how to write JDBC query results as csv, including column names?

  • 2018-01-02 18:53:54
  • ab11
  • 234 View
  • 0 Score
  • 2 Answer
  • Tags:   jmeter

1 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] overwrite csv file using jmeter beanshell

1 Answered Questions

Response data is not displayed in .jtl file in Jmeter

  • 2015-08-10 04:08:22
  • Raj
  • 1038 View
  • 1 Score
  • 1 Answer
  • Tags:   jmeter

1 Answered Questions

2 Answered Questions

JMeter - CSV Data Set Config failing to find CSV

  • 2012-05-30 14:22:44
  • Enrique
  • 5239 View
  • 0 Score
  • 2 Answer
  • Tags:   jmeter

1 Answered Questions

jMeter CSV_Data_Set config and XML dynamic binding

  • 2015-03-21 04:53:18
  • Samant
  • 619 View
  • 0 Score
  • 1 Answer
  • Tags:   jmeter

Sponsored Content