Click here to Skip to main content
15,797,923 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to write the data in excel or CSV file using beanshell. But i am not able to write the data in excel sheet at particular cell.

Any help would be appreciated.

What I have tried:

import net.minidev.json.parser.JSONParser;
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONObject;
import com.eclipsesource.json.*;
import org.json.simple.JSONArray;

var response = prev.getResponseDataAsString(); //Get response of the API;
f = new FileOutputStream("C:/Users/adityak/Desktop/K/app.csv", true);
p = new PrintStream(f);

This writes the data to CSV file but unable to write at particular cell.
Updated 13-Jun-18 4:59am
Jochen Arndt 13-Jun-18 6:26am    
It depends on what pair.getValue() is returning which I don't know.

With a CSV file, you would probably only need the plain value as string (the field names can be optionally passed on the first line of the file).

Note also that your code has a trailing comma on all lines. Append that before the value when not the first value on a line.
Adityakumar2318 13-Jun-18 9:49am    
Now i am able to write the response data in CSV file. but not able to write at particular cell.
Richard MacCutchan 13-Jun-18 10:27am    
CSV files are just lines of text containing fields separated by commas, e.g.:
John, Smith, 040768, $57332, "Senior Sales Operative"
Ech line is a row, and each field is a column. If you want the data to appear in a specific cell of the spreadsheet then you need to count the rows and columns as you create the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900