Wednesday, 11 February 2015

Export data from AX as HTML file

Hi All

Following code is to export data from AX as HTML file


static void HtmlCustomerWriter(Args _args)
{

    System.IO.StreamWriter sw;
    InteropPermission perm = new InteropPermission(InteropKind::ClrInterop);
    CustTable   custTable;
   
    perm.assert();

    sw = new System.IO.StreamWriter(@"C:\test.Html");
   
    //Html write
    sw.WriteLine("<Html>");

    // Header part
    sw.WriteLine("<head>");
    sw.WriteLine("<title>Cutomer list</title>");  
    sw.WriteLine("</head>");

    // body part
    sw.WriteLine("<body>");  
   
    //Data in table format form custtable
    sw.WriteLine("<table>");
    while select crossCompany CustTable
    {
      sw.WriteLine("<tr><td>");
      sw.WriteLine(custTable.AccountNum);
      sw.WriteLine("</td><td>");
      sw.WriteLine(custTable.name());
      sw.WriteLine("</td></tr>");
    }

    sw.WriteLine("</table>");
    sw.WriteLine("</body>");


    sw.WriteLine("</Html>");
    sw.Flush();
    sw.Close();
    sw.Dispose();

    CodeAccessPermission::revertAssert();

}