• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

DelphiTXLSReadWriteII2读取数据

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

TXLSReadWriteII2 按行读取数据(写得复杂了点,实际项目中的,可以自己简化)

 

procedure TformMain.LoadGeneralObject(_type, _col, _row: Integer; _filename: AnsiString);

var

  xls: TXLSReadWriteII2;

  i: integer;

  dataRec: TDataRec;

  reportedRec: TReportedRec;

 

  RegistrationNO: AnsiString;

  StartstopTime: AnsiString;

  LastTime: AnsiString;

  Ownedcompanies: AnsiString;

  SimNO: AnsiString;

 

  TerminalIDHex: AnsiString;

  TerminalIDStr: AnsiString;

begin

  RzProgressBar1.Percent := 0;

  i := 0;

 

  xls := TXLSReadWriteII2.Create(Self);

  try

    Xls.Filename := _filename;

    Xls.Read;  //必须的

 

    Xls.Sheet[0].LastCol := _col;

    Xls.Sheet[0].LastRow := _row;

 

    case _type of

      1: i := 1;

      2: i := 2;

    end;

 

    while i <= Xls.Sheet[0].LastRow do

    begin

      case _type of

        1:

          begin

            reportedRec.ID := StrToIntDef(XLS.Sheets[0].AsFmtString[0, i], 0);

            Ownedcompanies := XLS.Sheets[0].AsFmtString[1, i];

            reportedRec.Ownedcompanies := FilterChar(Ownedcompanies);

            RegistrationNO := XLS.Sheets[0].AsFmtString[2, i];

            reportedRec.RegistrationNO := Q_StrTok1(RegistrationNO, '-');

            reportedRec.Industry := FilterChar(XLS.Sheets[0].AsFmtString[3, i]);

            reportedRec.Dealer := FilterChar(XLS.Sheets[0].AsFmtString[4, i]);

            reportedRec.SimNO := FilterChar(XLS.Sheets[0].AsFmtString[6, i]);

            reportedRec.TerminalFactory := FilterChar(XLS.Sheets[0].AsFmtString[7, i]);

            TerminalIDHex := FilterChar(XLS.Sheets[0].AsFmtString[8, i]);

            TerminalIDStr := Trim(Q_StrTok1(TerminalIDHex, '/'));

            reportedRec.TerminalIDInt := StrToInt64Def(TerminalIDStr, 0);

            TerminalIDHex := Trim(TerminalIDHex);

            Q_Delete(TerminalIDHex, 1, 2);

            reportedRec.TerminalIDHex := TerminalIDHex;

            reportedRec.Reported := XLS.Sheets[0].AsFmtString[9, i] = '已上报';

            reportedRec.isReported := True;

 

            AddReportInfo(reportedRec);

            inc(i, 2);

          end;

        2:

          begin

            dataRec.ID := StrToIntDef(XLS.Sheets[0].AsFmtString[0, i], 0);

            dataRec.VendorID := StrToIntDef(XLS.Sheets[0].AsFmtString[1, i], 0);

            dataRec.TerminalIDHex := XLS.Sheets[0].AsFmtString[2, i];

            TerminalIDStr := XLS.Sheets[0].AsFmtString[3, i];

            dataRec.TerminalIDInt := StrToIntDef(TerminalIDStr, 0);

            dataRec.TerminalKind := IfThen(Q_CopyLeft(TerminalIDStr, 1) = '4', 600, 700);

            dataRec.CenterID := StrToIntDef(XLS.Sheets[0].AsFmtString[4, i], 0);

            dataRec.CommType := XLS.Sheets[0].AsFmtString[5, i];

            Ownedcompanies := XLS.Sheets[0].AsFmtString[6, i];

            dataRec.Ownedcompanies := FilterChar(Ownedcompanies);

            RegistrationNO := XLS.Sheets[0].AsFmtString[7, i];

            if Trim(RegistrationNO) = '' then

              dataRec.RegistrationNO := ''

            else

              dataRec.RegistrationNO := Q_StrTok1(RegistrationNO, '-');

 

            SimNO := XLS.Sheets[0].AsFmtString[8, i];

            dataRec.SimNO := FilterChar(SimNO);

            dataRec.Reported := XLS.Sheets[0].AsFmtString[13, i] = '√';

            dataRec.BackInfo := XLS.Sheets[0].AsFmtString[14, i] = '√';

            StartstopTime := XLS.Sheets[0].AsFmtString[15, i];

            if StartstopTime = '' then

            begin

              dataRec.StartstopTime := '';

              dataRec.LastTime := 0;

            end

            else

            begin

              StartstopTime := FilterChar(StartstopTime);

              dataRec.StartstopTime := StartstopTime;

              Q_StrTok1(StartstopTime, '~');

              LastTime := FormatDateTime('yyyy-', Now) + StartstopTime;

              dataRec.LastTime := StrToDateTime(LastTime);

            end;

            dataRec.RealTime := 0;

 

            AddCarGeneralInfo(dataRec);

            inc(i);

          end;

      end;

 

      doOnProgressBar(100 * i div Xls.Sheet[0].LastRow);

    end;

  finally

    xls.Free;

  end;

end;


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap