18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Writing Data into CSV file
Hi
how to write data into CSV file , am making use of _writeCSVFile(array2d, filePath) api , but it is writing each individual character into a cell.
Ex:
part of my code is like this :
var $data=_readCSVFile("/home/trainee/sahi/userdata/scripts/csv_16th/test_csv_new_url.csv");
$keyword=$data[1][0];
_writeCSVFile($data[1][0],"/home/trainee/Desktop/write.csv")
when i run this code it will run successfully but the data (in this case its "url") will be printed in csv file like
u
r
l
Can you help me on how to print that "url" as a single value in a cell of CSV file. Here am saving a openoffice spreadsheet with .csv extension and making use of it as CSV file
how to write data into CSV file , am making use of _writeCSVFile(array2d, filePath) api , but it is writing each individual character into a cell.
Ex:
part of my code is like this :
var $data=_readCSVFile("/home/trainee/sahi/userdata/scripts/csv_16th/test_csv_new_url.csv");
$keyword=$data[1][0];
_writeCSVFile($data[1][0],"/home/trainee/Desktop/write.csv")
when i run this code it will run successfully but the data (in this case its "url") will be printed in csv file like
u
r
l
Can you help me on how to print that "url" as a single value in a cell of CSV file. Here am saving a openoffice spreadsheet with .csv extension and making use of it as CSV file
This discussion has been closed.
Comments
In order to write some data into CSV file,you should specify the array name and not a cell in array.Since your CSV file is intialized with the particular number of rows and columns,the script will try to divide the input and feed to all the columns.
Kindly try the below script and check if this solves issue.
Regards
Theeran
Please do not duplicate the post.
Regards
Sumitra
Thanks for your reply....
I tried the modified code , it prints the value("url") in a single cell, but along with that it will print all other data which is there in test_csv_new_url.csv file.
My scenario is, i want to print the first cell value of "test_csv_new_url.csv" only, in "write.csv" file.
or
I want to print the value of a variable Ex: var $keyword = "PASS"
in this case what should i mention for "array2d" field of _writeCSVFile(array2d, filePath) api.
Inorder to get only the first cell value from a CSV file,you should create a new 2darray and store the received values in its first column and pass it as a 2darray parameter by using _writeCSVFile() API.
Try the following code
Regards
Theeran
The code that you posted will again print all the data of first column, as because, there data of first column(of all rows) is assigned to the newly created array "$value" .
Can you suggest me what steps can i follow to go with second scenario that is :
To print the value of a variable Ex: var $keyword = "PASS"
in this case what should i mention for "array2d" field of _writeCSVFile(array2d, filePath) api.
Inorder to get only the first cell value of one CSV file to be printed in another CSV file,try the following code.
and with the case of your second scenario,try the following code,
Hope this would help you.
Regards
Theeran.
Its working, thanks a lot.....