Export a Local Html form data to CSV using Javascript or VBscript
13,268
I assume this is an IE-only question (VBScript). If so, you can use ActiveXObject called FileSystemObject.
JavaScript:
csv=[]; // Collect form values to this array.
function saveFile(csv){
var fso,oStream;
fso=new ActiveXObject('Scripting.FileSystemObject');
oStream=fso.OpenTextFile('absolute_file_path',8,true);
oStream.WriteLine(csv.join(','));
oStream.Close();
return;
}
function readFile(path){
var fso,iStream,n,csv=[];
fso=new ActiveXObject('Scripting.FileSystemObject');
iStream=fso.OpenTextFile(path,1,true);
for(n=0;!iStream.AtEndOfStream;n++){
csv[n]=iStream.ReadLine().split(',');
}
iStream.Close();
return csv;
}
You can read more about FileSystemObject in MSDN.
Author by
Admin
Updated on June 05, 2022Comments
-
Admin almost 2 years
I have created an HTML Form which will be used from a local computer and want the form data to be saved in CSV file.
Each time the form is submitted, it should add a line in the CSV file.
This needs to be run locally so cannot use PHP or JSP.
Any help or idea is appreciated.