table1里面有三个字段: x y z( N 型数据 )
现要将excel文件中的数据读入表中,请问如何实现?拜托了!(原表中记录为空)我用的一个opendialog1,和一个button1键组合将excel文件读入Ttable1(数据库为自带paradox)
现要将excel文件中的数据读入表中,请问如何实现?拜托了!(原表中记录为空)我用的一个opendialog1,和一个button1键组合将excel文件读入Ttable1(数据库为自带paradox)
解决方案 »
- Delphi Spring Framework路在何方?欢迎大家各抒己见!
- delphi7怎样怎样制作在线升级程序??
- 如何利用语句往Excel里面写入内容????急!!!!!
- 简单问题,但是一直没有解决到。。。。高手赐教!!
- richedit中把其中内容拷贝成图片问题?
- 请问学数据库是不是一个程序员的基础?不学数据库不能学高级技术?不学数据库的程序员就没饭吃?
- 对于TToolButton这样没有Handle的控件要怎么发消息?在线等
- 为什么别人结贴了,且给了我一定的分数,为什么我的总信誉分总是不变?
- 一个简单的问题
- 程序执行到此显示没找到参数prmxm,大家帮我看看,谢了!
- 谁有JwaSocket包中的这个WINDEFINES.INC文件?
- 求一sql语句,谢谢!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls, DB, ADODB, Grids, DBGrids;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADOTable1: TADOTable;
DataSource1: TDataSource;
OpenDialog1: TOpenDialog;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
MSExcel: Variant;
i: Integer;
begin
OpenDialog1.Filter:='*.xls';
if OpenDialog1.Execute then
begin
ADOTable1.Close;
ADOTable1.Open;
MSExcel:=CreateOLEObject('Excel.Application');
MSExcel.WorkBooks.Open(OpenDialog1.FileName);
MSExcel.Visible:=False;
//从有数据的行逐行读入数据
for i:=1 to MSExcel.ActiveSheet.UsedRange.Rows.Count do
begin
ADOTable1.Insert;
ADOTable1.FieldByName('a').AsString := MSExcel.Cells[i,1].Value;
ADOTable1.FieldByName('b').AsString := MSExcel.Cells[i,2].Value;
//数据格式控制
//MSExcel.Cells[i,3].NumberFormat:='@';
ADOTable1.FieldByName('c').AsString := MSExcel.Cells[i,3].Value;
ADOTable1.FieldByName('d').AsString := MSExcel.Cells[i,4].Value;
ADOTable1.post;
end;
MSExcel.ActiveWorkBook.Close;
MSExcel.Quit;
end;
end;
end.
//从Excel写数据到Access库
prodedure ExcelToMdb(EXLfile:string;);
var
sheet,XLApp,workbook : variant;
iRow,MaxRow:integer;
begin
screen.Cursor:=crHourGlass;
try
//创建对象
XLApp:=createOleObject('Excel.Application');
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=false;
XLApp.WorkBooks.Add(EXLfile);
workbook := XLApp.workbooks[1];
sheet:=workbook.worksheets[1];
//sheet:=XLApp.WorkBooks[1].worksheets[1];
//取得最大行数 maxRow
XLApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=XLApp.ActiveCell.Row; //最大行数
//写数据到Access库
ADOTable1.open;
for iRow:=2 to MaxRow do
if sheet.cells[iRow,1]<>'' then //关键字不为空
begin
ADOTable1.Append ;
ADOTable1.fieldByName('ID').asInteger:=
strToInt(sheet.cells[iRow,1]);
ADOTable1.fieldByName('code').asString:=sheet.cells[iRow,2]; //编码
ADOTable1.fieldByName('name').asString:=sheet.cells[iRow,3]; //名称
ADOTable1.post;
end;
finally
if not VarIsEmpty(XLApp) then begin //释放对象
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=true;
XLApp.quit;
end;
screen.Cursor:=crDefault;
end;
end;
//从Excel写数据到Access库
prodedure ExcelToMdb(EXLfile:string;);
var
sheet,XLApp,workbook : variant;
iRow,MaxRow:integer;
begin
screen.Cursor:=crHourGlass;
try
//创建对象
XLApp:=createOleObject('Excel.Application');
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=false;
XLApp.WorkBooks.Add(EXLfile);
workbook := XLApp.workbooks[1];
sheet:=workbook.worksheets[1];
//sheet:=XLApp.WorkBooks[1].worksheets[1];
//取得最大行数 maxRow
XLApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=XLApp.ActiveCell.Row; //最大行数
//写数据到Access库
ADOTable1.open;
for iRow:=2 to MaxRow do
if sheet.cells[iRow,1]<>'' then //关键字不为空
begin
ADOTable1.Append ;
ADOTable1.fieldByName('ID').asInteger:=
strToInt(sheet.cells[iRow,1]);
ADOTable1.fieldByName('code').asString:=sheet.cells[iRow,2]; //编码
ADOTable1.fieldByName('name').asString:=sheet.cells[iRow,3]; //名称
ADOTable1.post;
end;
finally
if not VarIsEmpty(XLApp) then begin //释放对象
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=true;
XLApp.quit;
end;
screen.Cursor:=crDefault;
end;
end;