那等同于读取一个excel文件,然后吧数据导入到数据库中,其实写入数据库的操作和一般的数据库程序没有什么不同,关键在于读取excel的数据:{以下是把excel数据写到文本文件的,自己修改一下吧}
procedure TForm1.Button2Click(Sender: TObject);
var
I,J : integer;
TxtFile : TextFile;
TmpString : String;
begin
try
if VarIsEmpty(XlsApp) then
XlsApp := CreateOleObject('Excel.Application');
XlsSheet := XlsApp.workbooks.open('c:\my documents\book3.xls'); AssignFile(TxtFile,'C:\My Documents\Test.txt');
Rewrite(TxtFile);
try
for I := 3 to 21 do
begin
TmpString := '';
for J := 1 to 5 do
begin
TmpString := TmpString + XlsSheet.ActiveSheet.Cells[I,J].Text + '|';
end;
Writeln(TxtFile,Tmpstring);
end;
finally
CloseFile(TxtFile);
end;
XlsApp.Visible := true;
except
XlsSheet.close;
XlsApp.Application.quit;
XlsApp := Unassigned;
XlsSheet := Unassigned;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I,J : integer;
TxtFile : TextFile;
TmpString : String;
begin
try
if VarIsEmpty(XlsApp) then
XlsApp := CreateOleObject('Excel.Application');
XlsSheet := XlsApp.workbooks.open('c:\my documents\book3.xls'); AssignFile(TxtFile,'C:\My Documents\Test.txt');
Rewrite(TxtFile);
try
for I := 3 to 21 do
begin
TmpString := '';
for J := 1 to 5 do
begin
TmpString := TmpString + XlsSheet.ActiveSheet.Cells[I,J].Text + '|';
end;
Writeln(TxtFile,Tmpstring);
end;
finally
CloseFile(TxtFile);
end;
XlsApp.Visible := true;
except
XlsSheet.close;
XlsApp.Application.quit;
XlsApp := Unassigned;
XlsSheet := Unassigned;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货