Hello, i am trying to read from a .csv file which is in a defined location and thereafter manipulate the data.
I used to convert the .csv file manually to a .xls file and then import the.xls file and use it with the partial code below, however the new requirement is to read the .csv file directly.
Can anybody assist with the correct methods to read a .csv file and iterate through the lines.
Thanks
Michael
<=============>
var ImportFile = getpathandfile();
if(ImportFile!=null)
{
var Excelapp = Context.getExcelReader(ImportFile.getData());
var sheets = Excelapp.getSheets();
var currentSheet = sheets[0];
//var sheetname = currentSheet.getName();
var dataRows = currentSheet.getRows ( );
for(var m=0;m<dataRows.length;m++)
{
var data = new classData();
data.vAppName = dataRows[m].getCellAt(0).getCellValue ( );
data.vOS = dataRows[m].getCellAt(1).getCellValue ( );
data.vHardwareVendor = dataRows[m].getCellAt(2).getCellValue ( );
dataItems.push(data);
}
Hi Michael,
To read a CSV file, you have to open it and read it line by line :
Example, here I get all lines in an array :
var arrayLines = new Array(); var Files = Dialogs.getFilePath("", "*.csv", "I:\\BPMap\\1_clients\\CNP\\Organigramme", "Get SAP extraction Excel file", 0); //Open a browser on the client side if(Files != null){ var file = Files[0]; var data = file.getData(); var fstream = new java.io.ByteArrayInputStream(data); var inputstream = java.io.DataInputStream(fstream); var bufferReader = java.io.BufferedReader(new java.io.InputStreamReader(inputstream)); var strLine = ""; while((strLine = bufferReader.readLine()) != null){ arrayLines.push(strLine); } }
Hope that helps.
Best Regards