Buttons()<<mbOK.O): if(Str【il==T.t|eStr【il) l i++: //启动Excel应用程序f臣不显示 else Ex.OlePropertySet(。Visible',false); { 册丁开指定的文件 if(i==1) Ex.OlePropertyGet('WorkBooks。).OleFunction(。Open。, i++: 0penDialogl—->FileName.c_strO); else Wb=Ex.OlePropertyGet(。ActiveWorkBook。): { Sh=Wb.OlePropertyGet(。ActiveSheet。): IsMatch=false; //读取表格第一行前7个单元格内容,用于判断表格文 MessageDlg I。文件格式不匹配!。,mtError, //件格式是否正确TMsgDIgButtonsO<<mbOK.O): AnsiString Str[7]; break; Str[O]=Sh.OlePropertyGet(。Cells。。1,1).OlePropertyGet(。 l Value。): l Str[1】=Sh.OlePropertyGet(。Cells',1.2).OlePropertyGet(。 l Value。): if(IsMatch)//如果文件格式匹配,则导入数据 Str[2]=Sh.OlePropertyGet(‘Cells',1,3).OlePropertyGet(。 { Value‘):TOuery+Queryl=newTQuery(this); Str[3]=Sh.OlePropertyGet(。Cells',1.4).OlePropertyGet(。 //RequestLive属性用于确定是否希望从查询指令中 Value。): Value。): Value。): Str[4]=Sh.OlePropertyGet(。Cells',1.5).OlePropertyGet(。 Str[5]=Sh.OlePropertyGet(。Cells',1.6).OlePropertyGet(。 Str[6]=Sh.OlePropertyGet(。Cells",1.7).OlePropertyGet(‘ ,/获取可读可写的查询结果, ,/缺省设置为假,表示查询结果只读。如果要使记录 ,,能够编辑,需要设置该属性为真。 ,,这里,要写入数据,故设罱为真。 Queryl一>RequestLive=true: Queryl一>DatabaseName=。D:W: Ouewl..>Close(); Queryl一>SQL一>Clear(); Quell一>SQL一>Add(。select’from studentinfo.db。): Queryl一>Open(): int RowCount; /,返同ExceI工作表的行数 RowCount=Sh.OlePropertyGet(。UsedRange。) OlePropenyGet(。Rows。). OlePropertyGet(。Count。): AnsiString InputStr[7];//当前导入信息 AnsiString FilterString;//筛选条件 int RecCount; int AddCount=0;,/添加记录数量 for(int j=O;j<RowCount一1:j++) { ,/读取学号 InputStr【0】=Sh.OlePropertyGet(‘Cells。,j+2,1) OlePropertyGet(“Value。): 删且织筛选条件字符串 FilterString=Queryl->Fields->Fields 10】一> FieldName+。=。+StrToInt(InputStr[0]); Queryl->Filtered=false; Quell->Filter=FilterString; Quell一>Filtered=true: II半JJ断记录是否存在 RecCount=Queryl..>RecordCount; ifIRecCount==0)//不存在 { Queryl—->Close(); Queryl一>SQL一>Clear(); Queryl一>SQL一>Add (。select + from studentinfo.db。): Queryl一>OpenI): /厂读取姓名 lnputStr 11 1=Sh.OleProperb/rGet OlePropertyGet('Value。): ,/读取性别 InputStr【2】=Sh.OlePropertyGet OlePropertyGet(。Value。): //读取性别 InputStr 13】=Sh.OlePropertyGet OlePropertyGet(。Value。): ,/i卖取性别 InputStr【4l=Sh.OlePropertyGet OlePropertyGet(。Value。): ∥读取性别 InputStr f5J5=Sh.OlePropertyrGet i曼/盎嚣与簟耥 《。Cells‘,j+2,2). (。Cells。,j+2,3) (。Cells。,j+2.4) (。Cells。,j+2,5) (。Cells。.j+2,6) 密集 OlePropertyGet(。Value。J: //i卖取性别 InputStr 16】=Sh.OlePropertyGet(。Cells。,j+2,7) OlePropertyGet(。Value。): ,,在数据表最后添加一个空记录 Quell->Append(); ∥将数据赋给数据记录各字段 Queryl一>Fields一>Fields[0]一>V8Iue=InputStr【O】: Quell一>Fields一>Fields[1】一>VaIue=InputStr【1 l: Quell一>Fields一>Fields[2]一>VaIue=InputStr【2l: Queryl一>FieIds一>FieIds【3卜.>Value=lnputStr[3]; Queryl一>FieIds一>FieIdsf4】一>VaIue=InputStr【4J: Queryl->Fields一>Fields[5]一>VaIue=InputStr【5】: Queryl一>FieIds一>FieIdsf6】一>Value=InputStr【6】: //提交修改 Queryl一>Postl): IlgWu的记录数加1 AddCount++; l Queryl->Filtered=faIse; } delete OpenDialogl: delete Queryl: AnsiString Msg=。共添加。+IntToStr(AddCount)+。条记录!‘: |