nativeexcel将excel导入数据集
nativeexcel将excel导入数据集
uses nexcel;
procedure Tfgoods.daoruExecute(Sender: TObject);
var
od: TOpenDialog;
wb: IXLSWorkbook;
ws: IXLSWorksheet;
irow: integer;
v: Variant;
begin
od := TOpenDialog.Create(nil);
od.Filter := 'xls|*.xls';
wb := TXLSWorkbook.Create;
if od.Execute then
begin
wb.Open(od.FileName);
ws := wb.WorkSheets[1];
if ws.UsedRange.Rows.Count = 0 then
Exit;
// 商品名称 条码 进价 售价 单位
for irow := 2 to ws.UsedRange.Rows[1].Count - 2 do // 遍历行
begin
ADOQuery1.Append; // 追加
ADOQuery1.FieldByName('goodsid').Text := GetGoodsId;
v := ws.UsedRange.Cells[irow, 1].Value;
if not VarIsNull(v) then
ADOQuery1.FieldByName('goodsname').Text := v;
v := ws.UsedRange.Cells[irow, 2].Value;
if not VarIsNull(v) then
ADOQuery1.FieldByName('barcode').Text := v;
v := ws.UsedRange.Cells[irow, 3].Value;
if not VarIsNull(v) then
ADOQuery1.FieldByName('jingjia').Text := v;
v := ws.UsedRange.Cells[irow, 4].Value;
if not VarIsNull(v) then
ADOQuery1.FieldByName('shoujia').Text := v;
v := ws.UsedRange.Cells[irow, 5].Value;
if not VarIsNull(v) then
ADOQuery1.FieldByName('unitname').Text := v;
ADOQuery1.Post;
end;
end;
wb.Close;
od.Free;
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/7905244.html