zoukankan      html  css  js  c++  java
  • 导入数据到excel

    Quiet often we get the request from the clients that they wish if the reports or query data they design can be seen in excel in the Excel formatted way. Though the standard reports output can be sent to Excel  but that is not formatted . Almost all the enquiries have a button to export the grid data to Excel but that gives them limitation of only the GRID data.

    We have recently given the following two solutions in different scenarios to different clients. Where the data is not very huge ( the user is expecting a couple of hundred lines as a query output then the following solution will work nice.

    Dynamics AX’s classes prefixed with SysExcel actually do the export to excel. We would use these classes and create a small list of customers alongwith the itemIds they have bought or placed order for.

    Open the AOT. Create a shared project e.g. SD_ExcelExport

    Create the a new class as shown below :

    =================================================================================

    class SDExcelExport
    {
    }
    
    
    public static void main(Args args)
    {
    
        CustTable custTable;
        SysExcelApplication application;
        SysExcelWorkBooks    workbooks;
        SysExcelWorkBook     workbook;
        SysExcelWorksheets  worksheets;
        sysExcelWorksheet   worksheet;
        SysExcelCells       cells;
        SysExcelCell        cell;
        int                 row;
    
        ;
    
        application = SysExcelApplication::construct();
        workbooks = application.workbooks(); //gets the workbook object
        workbook = workbooks.add();  // creates a new workbook
        worksheets = workbook.worksheets(); //gets the worksheets object
        worksheet = worksheets.itemFromNum(1);//Selects the first worksheet in the workbook to insert data
        cells = worksheet.cells();
        cells.range('A:A').numberFormat('@');  // numberFormat ‘@’ is to insert data as Text
    
        while select custTable
        //The following loop will provide the data to be populated in each column
        {
            row++;
            cell = cells.item(row,1);
            cell.value(custTable.AccountNum);
            cell = cells.item(row,2);
            cell.value(custTable.Name);
            cell = cells.item(row,3);
            cell.value(CustTable.CustGroup);
            cell = cells.item(row,4);
            cell.value(CustTable.Currency);
            cell = cells.item(row,5);
            cell.value(CustTable.CreditMax);
            cell = cells.item(row,6);
            cell.value(CustTable.CreditRating);
        }
        application.visible(true);  '// opens the excel worksheet
    }

    =================================================================================

  • 相关阅读:
    C#,调用dll产生 "尝试读取或写入受保护的内存 。这通常指示其他内存已损坏。"的问题
    【调试输出】与【输出调试文本】的区别
    二、易语言 api 相关
    E4A 与JS交互事件无反应
    变量循环首、判断循环首、枚举循环首
    文本的操作:子文本替换、分割文本、取文本中间、取指定文本
    变量、&连接、函数与过程、按下某键
    淘宝客推广链接如何转换?
    淘宝客知道这几个ID,收入将会提高50%
    文件已经加入.gitignore但是vs并没有显示文件处于ignore状态
  • 原文地址:https://www.cnblogs.com/perock/p/2383100.html
Copyright © 2011-2022 走看看