How to write data to csv file using Java script?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to write data to csv file using Java script?
Hello All,
I need help in writing values to csv file.My code is as below:
Driver = DDT.CSVDriver("C:/test.csv");
while(!Driver.EOF())
{
rowValue = Driver.Value("1stcolumn");
columnValue = Driver.Value("2ndcolumn");
// here I want to write some data to 3rd column based on the row., can anyone suggest me how to open csv file and //write in java script?
Driver.Next();
}
Thank you.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CSV driver doesn't support data writing (as well as other DDT drivers), you need to open the file as usual text file and write raw data into it.
Gennadiy Alpaev
Software Testing Automation Tips - my new book
TestComplete Cookbook is published!
About Community Experts
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To build on what @karkadil has indicated, there are many ways of doing precisely what he suggests. One such way is to use the aqFile scripting object. The way I'd do it is
1) Open the file to be read using aqFile.OpenTextFile
2) Open another new file as writable for your output
3) Use ReadLn to read the columns and immediately write it out to the new file
4) Start a "while not end of file" loop
5) Use ReadLn to read a line of data
6) Modify what is read in to include your value you want for the third column
7) Use WriteLn to output to the new file
😎 After the loop is finished, close both files.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe you should be able to connect to a csv file with ADO like you can with and excel file, then you could loop through rows and perform update statments like you can with a normal SQL database. I haven't had a chance to test this theory with a CSV but I know it works fine with excel.
Thanks,
Carson
Click the Accept as Solution button if my answer has helped
