Friday, May 16, 2014

Create .csv file from data

    The following code shows how to create a csv file



    CommaIo file;
    container line;

    TableName table;

    FileIoPermission perm;

    #define.ExampleFile(@"c:\test\filename.csv")

    #File




    perm = new FileIoPermission(#ExampleFile, #io_write);

    perm.assert();







    file = new CommaIo(#ExampleFile, #io_write);

    file.outFieldDelimiter(',');// for semicolon separator




    if (!file || file.status() != IO_Status::Ok)

    {

        throw error("File cannot be opened.");

    }

    while select spools

    {

        line = [table.fieldName1, table.fieldName2, table.fieldName3, variable];

        file.writeExp(line);

    }




    CodeAccessPermission::revertAssert();​

2 comments: