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

  • 相关阅读:
    K好数
    最大最小公倍数
    十六进制转十进制
    利用malloc定义数组
    01字串
    ubuntu 14.04 下jdk和sdk+eclipse 的配置
    Mysql3
    求最大连续子串
    UC笔试
    java实现随机洗牌算法
  • 原文地址:https://www.cnblogs.com/sxypeace/p/3568625.html
Copyright © 2020-2023  润新知