G
guguda
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var ExcelApp,MyWorkBook: OLEVariant;
i: Integer;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件请确认已经安装EXCEL.','',mb_OK+mb_IconStop);
Exit;
end;
if OpenDialog1.Execute then
MyworkBook:= ExcelApp.workBooks.Open(OpenDialog1.FileName);
i:=1;
while trim(string(MyWorkBook.WorkSheets[1].item[i,1]))<>''do
adotable1.Append;
adotable1.FieldByName('Name').AsString := MyWorkBook.WorkSheets[1].Cells[i,1].Value;
adotable1.FieldByName('type').AsString := MyWorkBook.WorkSheets[1].Cells[i,2].Value;
adotable1.FieldByName('area').AsString := MyWorkBook.WorkSheets[1].Cells[i,3].Value;
adotable1.FieldByName('Area_no').AsString := MyWorkBook.WorkSheets[1].Cells[i,4].Value;
adotable1.FieldByName('piece').AsString := MyWorkBook.WorkSheets[1].Cells[i,5].Value;
adotable1.FieldByName('min').AsString := MyWorkBook.WorkSheets[1].Cells[i,6].Value;
adotable1.FieldByName('fee').AsString := MyWorkBook.WorkSheets[1].Cells[i,7].Value;
inc(i);
end;
ExcelApp:=Unassigned;
var ExcelApp,MyWorkBook: OLEVariant;
i: Integer;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件请确认已经安装EXCEL.','',mb_OK+mb_IconStop);
Exit;
end;
if OpenDialog1.Execute then
MyworkBook:= ExcelApp.workBooks.Open(OpenDialog1.FileName);
i:=1;
while trim(string(MyWorkBook.WorkSheets[1].item[i,1]))<>''do
adotable1.Append;
adotable1.FieldByName('Name').AsString := MyWorkBook.WorkSheets[1].Cells[i,1].Value;
adotable1.FieldByName('type').AsString := MyWorkBook.WorkSheets[1].Cells[i,2].Value;
adotable1.FieldByName('area').AsString := MyWorkBook.WorkSheets[1].Cells[i,3].Value;
adotable1.FieldByName('Area_no').AsString := MyWorkBook.WorkSheets[1].Cells[i,4].Value;
adotable1.FieldByName('piece').AsString := MyWorkBook.WorkSheets[1].Cells[i,5].Value;
adotable1.FieldByName('min').AsString := MyWorkBook.WorkSheets[1].Cells[i,6].Value;
adotable1.FieldByName('fee').AsString := MyWorkBook.WorkSheets[1].Cells[i,7].Value;
inc(i);
end;
ExcelApp:=Unassigned;