try
Screen
.
Cursor := crHourGlass;
try
OpenADOQuery(DM
.
QryTmp,
'select rq from tpJiHua where rq = '
''
+ Trim(ExcelApp
.
Cells[
2
,
1
].Value) +
''
''
);
if
DM
.
QryTmp
.
IsEmpty
then
begin
for
i :=
2
to
ExcelApp
.
ActiveSheet
.
UsedRange
.
Rows
.
Count
do
begin
rq := Trim(ExcelApp
.
Cells[i,
1
].Value);
pf:= Trim(ExcelApp
.
Cells[i,
2
].Value);
sl:= VarToStr(ExcelApp
.
Cells[i,
3
].Value);
with
DM
.
QryTmp
do
begin
Close;
SQL
.
Clear;
SQL
.
Add(
'Insert into tpJiHua(rq, pf, zljh)'
);
SQL
.
Add(
' values(:rq, :pf, :zljh)'
);
Parameters
.
parambyname(
'rq'
).Value := rq;
Parameters
.
parambyname(
'pf'
).Value := pf;
Parameters
.
parambyname(
'zljh'
).Value := sl;
ExecSQL;
OkNum := OkNum +
1
;
//更新成功数加1
end
;
end
;
end
else
begin
ErrorDlg(
'系统已有月份为:'
+ FormatDatetime(
'yyyy-mm'
,DM
.
QryTmp
.
FieldByName(
'rq'
).AsDateTime) +
' 的计划。'
);
exit;
end
;
InfoDlg(
'系统提示您:系统共成功导入'
+ IntToStr(OkNum) +
'条数据'
);
except
on
E: Exception
do
begin
ErrorDlg(
'系统提示您,数据导入失败,原因为:'
+ e
.
Message);
end
;
end
;
finally
//
ExcelApp
.
ActiveWorkBook
.
Close;
ExcelApp
.
Quit;
ExcelApp := Unassigned;
Screen
.
Cursor := crDefault;
end
;