try
myexcel := createoleobject('excel.application');
except
showmessage('没有安装Excel');
Exit;
end;
myexcel.WorkBooks.Open(opendialog1.FileName);
Sheet := myexcel.workbooks[1].worksheets[1];
//判断读入的exel是否符合要求
if sheet.usedRange.Cells.Columns.count = 11 then
begin
for i := 3 to sheet.usedRange.Cells.rows.count do
begin
with DM.QryDataSelect do
begin
Close;
SQL.Clear;
sqlstr := 'insert into UseMaterialtemp(Depart,Banzu,MName,MType,Amount,UseTerm,DrawData,LogoutData,DrawMan)';
sqlstr := sqlstr + 'values
Depart,:Banzu,:MName,:MType,:Amount ,:UseTerm,
rawData,:LogoutData,
rawMan)';
SQL.Add(sqlstr);
Parameters.ParamByName('Depart').Value := sheet.cells[i, 2].value;
Parameters.ParamByName('Banzu').Value := sheet.cells[i, 3].value;
Parameters.ParamByName('MName').Value := sheet.cells[i, 4].value;
Parameters.ParamByName('MType').Value := sheet.cells[i, 5].value;
Parameters.ParamByName('Amount').Value := sheet.cells[i, 6].value;
Parameters.ParamByName('UseTerm').Value := sheet.cells[i, 7].value;
Parameters.ParamByName('DrawData').Value := sheet.cells[i, 8].value;
Parameters.ParamByName('LogoutData').Value := sheet.cells[i, 9].value;
Parameters.ParamByName('DrawMan').Value := sheet.cells[i, 10].value;
try
ExecSQL;
except