用x++读取excel文件

void importFromExcel()
{
    str                 file;
    FileNameFilter      filter=["07-10",'*.xlsx',"97-02",'*.xls'];
    COMVariant          Variant;
    SysExcelApplication app;
    SysExcelWorkbooks   Workbooks;
    SysExcelWorkbook    Workbook;
    SysExcelWorksheets  Worksheets;
    SysExcelWorksheet   Worksheet;
    SysExcelCells       Cells;
    int                 i;
 
    str s;
    #excel
    try
    {
        //s = enum2str(bTable.NewItemType);//这个就是枚举字段 进行了转换没用
        file        = Winapi::getOpenFileName(0, filter, '', "Open Excel Files");
 
        app         = SysExcelApplication::construct();
        Workbooks   = app.Workbooks();
        Variant = new COMVariant();
        Variant.bStr(file);
        Workbook    = Workbooks.Add(Variant);
        Worksheets  = Workbook.worksheets();
        Worksheet   = worksheets.itemFromNum(1);
        Cells       = Worksheet.Cells();
 
        i = 2;
        //8:00-12:00
        //16:00-20:00
        while (cells.item(i,1).value().bStr() != "")
        {
            _attendee.clear();
            _attendee.initValue();
            _attendee.hrmCourseId =_courseTable.hrmCourseId;
            _attendee.hrmVirtualNetworkId = cells.item(i,1).value().bStr();
             element.checkAttendee(cells.item(i,3).value().bStr());
 
            if(_attendee.validateWrite())
                _attendee.insert();
 
 
            i++;
 
        }
    }
    catch
    {
        info("Nothing Uploaded");
    }
    app.quit();
}​
posted @ 2014-01-02 09:26  Huaen  阅读(261)  评论(0编辑  收藏  举报