AX 利用windows粘贴板功能实现批量数据快速导出EXCEL

static void test(Args _args)
{

    int     lineNum;
    int     titleLines;
    SysExcelApplication excel;
    SysExcelWorkbooks books;
    SysExcelWorkbook book;
    SysExcelWorksheets sheets;
    SysExcelWorksheet sheet;
    SysExcelRange columns;
    SysExcelRange column;
    SysExcelCells cells;
    SysExcelCell cell;
    SysExcelStyles ExcelStyles;
    SysExcelStyle ExcelStyle;
    SysExcelFont ExcelFont;

    COM     range;
    COM     ExcelCom;
    
    int newLines,beginLines;
    int maxLines = 1000;
    
    TextBuffer  txtBuffer;
    
    CustTable   ct;
    ;
    excel   = SysExcelApplication::construct();
    books   = excel.workbooks();
    book    = books.add();
    sheets  = book.worksheets();
    sheet   = sheets.itemFromNum(1);

    ExcelCOM   = sheet.comObject();

    txtBuffer = new TextBuffer();
    while select ct
    {
        linenum++;
        newLines++;
        
        txtBuffer.appendText( strfmt("%1	%2	%3
", ct.AccountNum ,ct.Name, ct.Email));
        if( newLines == maxLines)
        {
            txtBuffer.toClipboard();
            txtBuffer.setText("");
            beginLines = linenum+titleLines+1- newlines;
            range = sheet.range(strfmt("A%1" , beginLines)).comObject();
            range.Select();
            ExcelCOM.paste();
            
            newLines=0;
        }
    }
    if( newLines!=0)
    {
        txtBuffer.toClipboard();
        txtBuffer.setText("");
        beginLines = linenum+titleLines+1- newlines;
        range = sheet.range(strfmt("A%1" , beginLines)).comObject();
        range.Select();
        ExcelCOM.paste();
    
    }
    book.saveAs("C:\1abc.xls");
    excel.visible(true);
}

考虑到textBuffer能存储的文本长度有限,所以需要分批次将数据从textBuffer粘贴到Window粘贴板。

原文地址:https://www.cnblogs.com/sxypeace/p/3568625.html