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;
    }

  • 相关阅读:
    EMF介绍系列(一、EMF与MDA)
    EMF介绍系列(四、枚举类型、自定义类型和Map)
    使用osgi.util.NLS简化资源文件访问
    2012 定制化产品探讨(周金根).pdf
    敏捷个人理念与模型PPT及今年唯一一次的公开线上课堂
    生活:父与子三亚行
    与北邮学子交流成长,敏捷个人总体介绍 PPT
    敏捷个人教你如何制作2012生活看板
    敏捷个人架构图 V1.3
    敏捷个人微刊封面及敏捷个人使命和加入社区方式
  • 原文地址:https://www.cnblogs.com/perock/p/2375675.html
Copyright © 2011-2022 走看看