• Delphi TXLSReadWriteII2 读取数据


    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;

  • 相关阅读:
    NES游戏历史
    NES资料
    Spring的自动装配
    springmvc框架如何将模型数据传递给视图 也就是Model>view参数的传递
    拆分Spring的配置文件
    Springmvc框架前台传值给controller @Requestparam @RequestMapping
    SpringMVC框架传入Map集合
    SpringMVC框架使用注解编写的处理请求和映射@Controller @RequestMapping
    SpringMVC初尝试
    MVC设计模式
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/2547251.html
Copyright © 2020-2023  润新知