zoukankan      html  css  js  c++  java
  • 使用ExcelApplication读取Excel文件

    public static server PwC_Import readexcel(filenameopen _file)
    {
        #Excel
        #AviFiles
        SysExcelApplication          excelApp = SysExcelApplication::construct();
        SysOperationProgress         progress = new SysOperationProgress();
        SysExcelWorkSheet            excelWorksheet;
        SysExcelRange                excelRange;
        SysExcelCells                excelCells;
        SysExcelCell                 excelCell;
        ComVariant                   cellValue = new ComVariant() ;
        boolean                      Flag_Found ;
        PwC_Import                   PwC_ImportLocal;
        int                          colno, colno_excel, colno_grid;
        int                          i;
        int                          TotalRow ;
        str                          strvalue ;
        COMVariant                   VariantValue ;
        Description                  Error;

        excelApp.workbooks().open( _File);
        excelWorksheet = excelApp.worksheets().itemFromNum(1);
        excelCells = excelWorksheet.cells();
        startlengthyoperation();

        flag_found=true ; TotalRow=1 ;
        //________________________________________________________
        excelCell=excelWorksheet.cells().item(TotalRow+1,1);
        strvalue=StrUpr(excelCell.value().bStr());
        if(strvalue!="**********")
            {
            excelworksheet = null;
            excelapp.quit();
            Throw Error("Invalid Excel Template. Please use template specified");
            }
        //________________________________________________________
        progress.setCaption("Data Import");
        progress.setAnimation(#AviFormLetter);
        startlengthyoperation();
        ttsbegin;
        while (Flag_Found==true)
        {
        progress.setText(strfmt("Scanning Records %1", TotalRow));
        //Marked____________________________________________________
        PwC_ImportLocal.Marked                  =NoYes::Yes;
        //TransDate_________________________________________________
        if(excelWorksheet.cells().item( TotalRow+2,1).value().date())
            {
            PwC_ImportLocal.Transdate           =excelWorksheet.cells().item( TotalRow+2,1).value().date();
            }
        else
            {
            Error=Error+"Date ; ";
            PwC_ImportLocal.Transdate           =datenull();
            PwC_ImportLocal.Marked              =NoYes::No;
            }
         //Account___________________________________________________
        If(LedgerTable::exist(excelWorksheet.cells().item( TotalRow+2,2).value().bStr()))
            {
            PwC_ImportLocal.Account=excelWorksheet.cells().item( TotalRow+2,2).value().bStr();
            }
        else
            {
            Error                               =Error+"<A/C>; ";
            PwC_ImportLocal.Account             ="";
            PwC_ImportLocal.Marked              =NoYes::No;
            }
         //Transaction Text_____________________________________________
         PwC_ImportLocal.TransTxt               =excelWorksheet.cells().item( TotalRow+2,3).value().bStr();
         //Offset Account_______________________________________________
         If(LedgerTable::exist(excelWorksheet.cells().item( TotalRow+2,4).value().bStr()))
            {
            PwC_ImportLocal.OffsetAccount       =excelWorksheet.cells().item( TotalRow+2,4).value().bStr();
            }
        else
            {
            Error                               =Error+"<Offset A/C>; ";
            PwC_ImportLocal.OffsetAccount       ="";
            PwC_ImportLocal.Marked              =NoYes::No;
            }
        //Amount Check_________________________________________________
        if( (excelWorksheet.cells().item(TotalRow+2,5).value().double() && excelWorksheet.cells().item(TotalRow+2,6).value().double())   ||
            (!excelWorksheet.cells().item(TotalRow+2,5).value().double() && !excelWorksheet.cells().item(TotalRow+2,6).value().double())  )
            {
            Error                               =Error+"<Dr & Cr>; ";
            PwC_ImportLocal.Marked              =NoYes::No;
            }

        //DebitAmount__________________________________________________
        PwC_ImportLocal.Debit                   = excelWorksheet.cells().item(TotalRow+2,5).value().double();
        //Credit Amount________________________________________________
        PwC_ImportLocal.Credit                  = excelWorksheet.cells().item(TotalRow+2,6).value().double();
        //Dimensions___________________________________________________
        PwC_ImportLocal.Dimensions[1]           =excelWorksheet.cells().item(TotalRow+2,7).value().bStr();
        PwC_ImportLocal.Dimensions[2]           =excelWorksheet.cells().item(TotalRow+2,8).value().bStr();
        PwC_ImportLocal.Dimensions[3]           =excelWorksheet.cells().item(TotalRow+2,9).value().bStr();
        //Error Description____________________________________________
        PwC_ImportLocal.ErrorDesc=Error;

        Error="";  // Reset to Null

        TotalRow++;
        PwC_ImportLocal.insert();
        progress.incCount();

        if(excelWorksheet.cells().item(TotalRow+2,2).value().bstr()=="")
           Flag_Found=false;
        }
        ttscommit;
        endlengthyoperation();
        excelworksheet = null;
        excelapp.quit();

        return PwC_ImportLocal;
    }

  • 相关阅读:
    【CF1157F】Maximum Balanced Circle 求一个相邻元素之间绝对值为小于1的最大环
    南昌网络赛 Distance on the tree 主席树+树剖 (给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数。)
    P2486 [SDOI2011]染色(树剖)区间覆盖+区间的连续段(点权) && (边权)
    树链剖分
    南昌网络赛 I. Max answer (单调栈 + 线段树)
    HDU4641 || 6194多校 (后缀自动机-最少出现K次的字串个数 || 恰好出现K次字符串的个数)
    2019年华南理工大学程序设计竞赛(春季赛) 单身狗救星 (凸包+二分)
    2019年华南理工大学程序设计竞赛(春季赛) B 修仙时在做什么?有没有空?可以来炼丹吗?(思维建图搜索)
    数据结构-----顺序表的实现
    Java数据类型及运算
  • 原文地址:https://www.cnblogs.com/perock/p/2375675.html
Copyright © 2011-2022 走看看