Through following code we can read CSV files
or
Happy X++ coding!!!
static void ReadCsvFile(Args _args)
{
#File
IO iO;
CustAccount custAccount;
CustName custname;
FilenameOpen filename = "d:\\jit.csv";//To assign file name
Container record;
boolean first = true;
;
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
custAccount = conpeek(record, 1);//To peek record
custname = conpeek(record, 2);
info(strfmt('%1--%2',custAccount,custname));
}
}
}
}
or
static void TestCommaTextIO(Args _args)
{
#File
CommaTextIo commaTextIo;
FileIOPermission permission;
container containFromRead;
int x;
int cols;
;
permission = new FileIOPermission('c:\\junk\\mycsv.csv',#io_read);
permission.assert();
commaTextIo = new CommaTextIO('c:\\junk\\mycsv.csv','R');
containFromRead = commaTextIo.read();
While(containFromRead)
{
cols = conLen(containFromRead);
for(x=1;x<=cols;x++)
{
print conpeek(containFromRead,x);
}
containFromRead = commaTextIo.read();
}
pause;
commaTextIo = null;
}
Happy X++ coding!!!
Komentar
Posting Komentar