码迷,mamicode.com
首页 > 其他好文 > 详细

NativeExcel 读取文件

时间:2014-07-14 19:55:47      阅读:382      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   color   文件   os   

class function T_EShopDataBill.ImportData(const AFileName: String;
  AList: T_EShopDataModelList; var AErr: string): Boolean;
var
    Book: IXLSWorkbook;
    ws: IXLSWorksheet;
    i : Integer;
    nOrderIDRow,nTrackNoRow : Integer;
    obj : T_EShopDataModel;
    tmpIden,tmpTrackNo : String;
    sSql : String;
    tmpQry : TADOQuery;
begin
   Book := TXLSWorkbook.Create ;
   try
     i := Book.Open(AFileName);
     ws := Book.WorkSheets[1];

     if ws.UsedRange.Rows.Count = 0 then
       Exit;

     nOrderIDRow := 0;
     nTrackNoRow := 0;
     for I := 1 to ws.UsedRange.Rows[1].Count -1 do
     begin
        if nOrderIDRow = 0 then
            if CompareText( VarToStr( ws.UsedRange.Cells[1,i].Value),单据备注) = 0 then
              nOrderIDRow := i;

        if nTrackNoRow = 0 then
           if CompareText( VarToStr( ws.UsedRange.Cells[1,i].Value),运单编号) = 0 then
              nTrackNoRow := i;

        if (nOrderIDRow > 0 ) AND (nTrackNoRow > 0) then
          Break;
     end;

      // ShowInformationMsg(inttostr(nOrderIDRow)+ +IntTostr(nTrackNoRow));
     if (nOrderIDRow = 0) or (nTrackNoRow = 0) then
       Exit;


     for i := 2 to  ws.UsedRange.Rows.Count  do
     begin
        with ws.UsedRange do
        begin
          if VarIsNull(Cells[i,nTrackNoRow].Value) then
            Break;
          if VarIsNull(Cells[i,nOrderIDRow].Value) then
            Break;
        end;

        tmpTrackNo := ws.UsedRange.Cells[i,nTrackNoRow].Value;
        tmpIden := ws.UsedRange.Cells[i,nOrderIDRow].Value;

        if ( Trim(tmpTrackNo) = ‘‘) or (tmpIden = ‘‘) then
        begin
          Break;
        end;

        obj := T_EShopDataModel.Create;
        obj.fOrderID := tmpIden;
        obj.fTrackNo := tmpTrackNo;
        AList.List.Add(obj);
     end;
   finally
     Book.Close;
   end;
end

 

NativeExcel 读取文件,布布扣,bubuko.com

NativeExcel 读取文件

标签:winform   style   blog   color   文件   os   

原文地址:http://www.cnblogs.com/starluck/p/3842741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!