Write Data from Ax table to Excel Sheet x++

Static server void Salah_WriteFile(Args _args)

{

TextIo file;

Filename filenmae= @”C:/Temp”;

Salah_CarTable carTable;

container con;

FileIOPermission permission;

#File

try

{

// Create the permission class

permission = new FileIoPermission(filename, #io_write);

 

// Add a request for permission before new TextIo()

permission.assert();

 

// Create the TextIo object

file = new TextIo(filename, #io_write);

 

if (!file)

throw Exception::Error;

 

// Specify the delimiters

file.outRecordDelimiter(#delimiterCRLF);

file.outFieldDelimiter(“;”) ;

 

// Loop through the data source

while select carTable

{

 

// Empty the container

con = connull();

 

// Set the data into the container

con = conins(con, 1, carTable.CarId);

con = conins(con, 2, carTable.CarBrand);

con = conins(con, 3, carTable.Mileage);

con = conins(con, 4, carTable.Model);

con = conins(con, 5, carTable.ModelYear);

 

// Write the container to the file

file.writeExp(con);

}

catch(Exception::Error)

 

{

error(“You do not have access to write the file to the selected folder”);

}

// Revert the access privileges

CodeAccessPermission::revertAssert();

}

Leave Comment

Your email address will not be published. Required fields are marked *