• 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粘贴板。

  • 相关阅读:
    memcache启动程序/etc/sysconfig/memcached
    shell中的点号
    mysql监控
    secureCRT 中文乱码
    memcache key
    杀死所以数据库进程
    导出表记录
    重建二叉树
    从尾到头打印链表
    二维数组中的查找
  • 原文地址:https://www.cnblogs.com/sxypeace/p/3568625.html
Copyright © 2020-2023  润新知