Tuesday, November 6, 2012

Creating a comma-separated value file


class CreateCommaFile
{
}


public static client void main(Args _args)
{
    CommaTextIo file;
    container line;
    MainAccount mainAccount;
    ;
    #define.filename(@'C:\Temp\accounts.csv')
    #File
    file = new CommaTextIo(#filename, #io_write);
   
    if (!file || file.status() != IO_Status::Ok)
    {
        throw error("File cannot be opened.");
    }
   
    while select MainAccountId, Name from mainAccount
    {
        line = [mainAccount.MainAccountId, mainAccount.Name];
        file.writeExp(line);
    }
   
    info(strFmt("File %1 created.", #filename));
}  


No comments: