01)using TextBuffer class handle

 

//1,使用TextBuffer从Ax 2009中导出数据到CSV文件中:
//http://www.qiuhao.com/forum-redirect-tid-13763-goto-lastpost.html#lastpost
static void Jimmy_ExportToCSVFile01(Args _args)
{
    TextBuffer              textBuffer  = new TextBuffer();
    InventTable             inventTable;
    FileIoPermission        perm;
    counter                 Lines;

    #define.ExampleFile(@"c:\test.csv")
    #define.ExampleOpenMode("W")
;
    try
    {
        // Set code access permission to help protect the use of
        perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode);
        perm.assert();


        textBuffer.appendText("Item Id,");//must be "," suffix
        textBuffer.appendText("Item Name,");//must be "," suffix
        textBuffer.appendText("Item Type");
        textBuffer.appendText("\n");//next line must be "\n" suffix

        while select InventTable
            where  inventTable.ItemType == ItemType::BOM
            &&     inventTable.ItemId like "10*"
        {
            textBuffer.appendText(strfmt("%1,",inventTable.ItemId));

            textBuffer.appendText(strfmt("%1,",global::strReplace(inventTable.ItemName,",","")));//must be repace "," to ""

            textBuffer.appendText(enum2str(inventTable.ItemType));
            textBuffer.appendText("\n");
        }
        Lines = textBuffer.numLines();

        try
        {
            if (textBuffer.toFile(#ExampleFile))
                info( strfmt("File Generated as %1.total insert %2 Lines",#ExampleFile,Lines));
        }
        catch ( Exception::Error )
        {
            error ("Generated file error.");
        }
        // Close the code access permission scope.
        CodeAccessPermission::revertAssert();
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
}

相关文章:

  • 2021-10-31
  • 2021-09-17
  • 2022-12-23
  • 2021-04-05
  • 2021-04-30
  • 2021-04-15
  • 2021-08-06
  • 2021-12-12
猜你喜欢
  • 2021-07-08
  • 2021-08-14
  • 2021-06-27
  • 2021-11-15
  • 2022-12-23
  • 2021-06-09
  • 2021-12-18
相关资源
相似解决方案