delehi使用Ado方式读取EXCEL导入的Demo

原创 2015年11月20日 17:32:11

delehi使用Ado方式读取EXCEL导入的Demo


源码

unit UF_S_KH_DR;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ActnList, DB, ADODB, DBGridEhGrouping, ToolCtrlsEh,
  DBGridEhToolCtrls, DynVarsEh, StdCtrls, ComCtrls, GridsEh, DBAxisGridsEh,
  DBGridEh, exgrid, RapTree, FlytreePro, Mask, RzEdit, RzBtnEdt, ExtCtrls,
  RzTabs, Grids, DBGrids, RzCmboBx, ComObj, DateUtils, DBCtrls, DBNavPlus,
  HzSpell;

type
  TF_S_KH_DR = class(TForm)
    AQry_CSM: TADOQuery;
    Ds_CSM: TDataSource;
    ActionList1: TActionList;
    Act_Exit: TAction;
    Act_0_N: TAction;
    Act_1_P: TAction;
    Act_1_N: TAction;
    Act_2_P: TAction;
    Act_2_N: TAction;
    Act_3_P: TAction;
    Act_3_N: TAction;
    Act_GridConfig_AQryCSM: TAction;
    PM_Grid: TPopupMenu;
    N1: TMenuItem;
    AQry_DRM: TADOQuery;
    AQry_Tmp: TADOQuery;
    AQry_XZ: TADOQuery;
    PGC_Main: TRzPageControl;
    Tab0: TRzTabSheet;
    Pnl_0_Head: TPanel;
    Button2: TButton;
    Button3: TButton;
    Btn_0_Close: TButton;
    Panel1: TPanel;
    lbl_1: TLabel;
    Label1: TLabel;
    Label8: TLabel;
    Tab1: TRzTabSheet;
    Panel2: TPanel;
    Label3: TLabel;
    Label2: TLabel;
    Panel5: TPanel;
    Button1: TButton;
    Button4: TButton;
    Button5: TButton;
    DBGrd_CSM: TDBGridEh;
    Tab2: TRzTabSheet;
    Panel3: TPanel;
    Label5: TLabel;
    Label4: TLabel;
    Panel6: TPanel;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Panel8: TPanel;
    PB_JD: TProgressBar;
    Mem_JCTS: TMemo;
    Panel9: TPanel;
    Label6: TLabel;
    lbl_JD: TLabel;
    Tab3: TRzTabSheet;
    Panel4: TPanel;
    Label7: TLabel;
    Panel7: TPanel;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    dbgrd_1: TDBGrid;
    Edt_ExcelFileName: TRzButtonEdit;
    cbb_ExcelGZB: TRzComboBox;
    Chb_SY2003FS: TCheckBox;
    Ds_1: TDataSource;
    ACON_DBE: TADOConnection;
    AQRY_Excel: TADOQuery;
    stat_1: TStatusBar;
    Button12: TButton;
    Act_DCExcel_AQryCSM: TAction;
    Pb_Read: TProgressBar;
    AQry_DRCMD: TADOQuery;
    lb_ExcelJD: TLabel;
    Chb_ClearTable: TCheckBox;
    DBNavPlus1: TDBNavPlus;
    DBNavPlus2: TDBNavPlus;
    HzSpell1: THzSpell;
    procedure FormCreate(Sender: TObject);
    procedure Edt_ExcelFileNameButtonClick(Sender: TObject);
    procedure Act_ExitExecute(Sender: TObject);
    procedure cbb_ExcelGZBChange(Sender: TObject);
    procedure Ds_1DataChange(Sender: TObject; Field: TField);
    procedure Ds_1StateChange(Sender: TObject);
    procedure Ds_1UpdateData(Sender: TObject);
    procedure Act_0_NExecute(Sender: TObject);
    procedure Act_1_PExecute(Sender: TObject);
    procedure Act_1_NExecute(Sender: TObject);
    procedure Act_2_PExecute(Sender: TObject);
    procedure Act_2_NExecute(Sender: TObject);
    procedure Act_3_PExecute(Sender: TObject);
    procedure Act_3_NExecute(Sender: TObject);
    procedure Act_DCExcel_AQryCSMExecute(Sender: TObject);
    procedure Act_GridConfig_AQryCSMExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    FACon: TADOConnection;
    FSJOK: Boolean;


    procedure SetStatInfoByDataSet(ISBar: TStatusBar; IIndex: Integer; IDataSet: TDataSet);

  end;

function SetDsFDW(IDs: TDataSet; IFieldWidth: Integer): Boolean;

const
  //Excel连接
  FrmConStrE = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Extended Properties="Excel 8.0;HDR=YES;IMEX=1"';

  FrmConStrE2003 = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Extended Properties="Excel 8.0;HDR=YES;IMEX=1"';
  FrmConStrE2010 = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=''%s''; Extended Properties=''Excel 12.0;HDR=YES''';
   // FrmConStrE = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Extended Properties="Excel 8.0;HDR=YES;IMEX=1"';


implementation

uses
  U_DBSystem,
  U_Message,
  U_Grid,
  U_Report,
  U_Other;
{$R *.dfm}




function SetDsFDW(IDs: TDataSet; IFieldWidth: Integer): Boolean;
var
  i_c: Integer;
begin
  Result := False;
  if IDs.Active then
  begin
    for i_c := 0 to Ids.FieldCount - 1 do
      if IDs.Fields[i_c].DisplayWidth > IFieldWidth then
        IDs.Fields[i_c].DisplayWidth := IFieldWidth;
  end;
end;


procedure TF_S_KH_DR.SetStatInfoByDataSet(ISBar: TStatusBar; IIndex: Integer; IDataSet: TDataSet);
begin
  try
    ISBar.Panels[IIndex].Text := '';
    if IDataSet <> nil then
    begin
      if IDataSet.Active then
      begin
        if IDataSet.IsEmpty then
        begin
          ISBar.Panels[IIndex].Text := '0/0';
        end
        else
        begin

          ISBar.Panels[IIndex].Text := IntToStr(IDataSet.RecNo) + '/' + IntToStr(IDataSet.RecordCount);
        end;
      end;
    end;
  except
  end;
end;




procedure TF_S_KH_DR.FormCreate(Sender: TObject);
var
  i: integer;
begin
  Caption := '托收-客户基础数据-导入';
  Mem_JCTS.Clear;

  for i := 0 to Self.PGC_Main.PageCount - 1 do
  begin
    PGC_Main.Pages[i].TabVisible := False;
  end;
  PGC_Main.ActivePageIndex := 0;

  DBGrd_CSM.ReadOnly := True;
 // DBGrd_CSM.Options := EditFalse;
  DBGrd_CSM.Options := GridOptionsEditFalse;
  DBGrd_CSM.OptionsEh := GridOptionsEh;

  DBGrd_CSM.RowHeight := 18;
  DBGrd_CSM.RowSizingAllowed := True;

  DBGrd_CSM.TitleParams.MultiTitle := True;

  FSJOK := False;
end;

procedure TF_S_KH_DR.Act_ExitExecute(Sender: TObject);
begin
  Close;
end;

procedure TF_S_KH_DR.Edt_ExcelFileNameButtonClick(
  Sender: TObject);
begin
  with TOpenDialog.Create(Application) do
  begin
    try
     //  Filter := 'Excel文件(*.XLS)|*.XLS|所有文件(*.*)|*.*';

      Filter := 'Excel文件(2003/2010)(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件(*.*)|*.*';

      FilterIndex := 0;
      InitialDir := ExtractFilePath(Application.ExeName);
      if Trim(self.edt_ExcelFileName.Text) <> '' then
      begin
        FileName := Trim(self.edt_ExcelFileName.Text);
      end;

      if Execute then
      begin
        ACON_DBE.Close;
        ACON_DBE.ConnectionString := '';
        if Chb_SY2003FS.Checked then
        begin
          ACON_DBE.ConnectionString := Format(FrmConStrE2003, [FileName]);
        end
        else
        begin
          ACON_DBE.ConnectionString := Format(FrmConStrE2010, [FileName]);
        end;

        self.edt_ExcelFileName.Text := FileName;
        try
          ACON_DBE.Open;
          cbb_ExcelGZB.Clear;
          ACON_DBE.GetTableNames(cbb_ExcelGZB.Items, False);
          cbb_ExcelGZB.ItemIndex := 0;
          cbb_ExcelGZBChange(Sender);

        except
          cbb_ExcelGZB.Clear;
          AQRY_Excel.Close;
          ShowMessage('打开文件不成功.');
        end;

      end;
    finally
      Free;
    end;
  end;
end;



procedure TF_S_KH_DR.cbb_ExcelGZBChange(Sender: TObject);
var i_c: integer;
begin
  if self.cbb_ExcelGZB.Text <> '' then
  begin
    AQRY_Excel.Close;
    AQRY_Excel.SQL.Text := 'Select * From [' + Self.cbb_ExcelGZB.Text + ']';
    try
      AQRY_Excel.Open;
      SetDsFDW(AQRY_Excel, 22);
    except
      ShowMessage('打开Excel工作薄不成功!');
    end;
  end;
end;

procedure TF_S_KH_DR.Ds_1DataChange(Sender: TObject;
  Field: TField);
begin
  SetStatInfoByDataSet(Self.stat_1, 0, self.ds_1.DataSet);
end;

procedure TF_S_KH_DR.Ds_1StateChange(Sender: TObject);
begin
  SetStatInfoByDataSet(Self.stat_1, 0, self.ds_1.DataSet);
end;

procedure TF_S_KH_DR.Ds_1UpdateData(Sender: TObject);
begin
  SetStatInfoByDataSet(Self.stat_1, 0, self.ds_1.DataSet);
end;

procedure TF_S_KH_DR.Act_0_NExecute(Sender: TObject);
var
  i: integer;
  SJOK: Boolean;
  SJBH: Integer;
begin
  FSJOK := False;
  SJOK := True;
  AQRY_Excel.DisableControls;
  try

    FACon.BeginTrans;
    try

      {
      AQry_Tmp.Close;
      AQry_Tmp.Connection := FACon;
      AQry_Tmp.SQL.Text := 'Truncate table S_KH';
      AQry_Tmp.ExecSQL;
      AQry_Tmp.Close;
       }
      AQry_CSM.Close;
      AQry_CSM.Connection := FACon;
      AQry_CSM.SQL.Text := 'SELECT * '
        + ' From S_KH_YHTSHT'
        + ' WHERE 1=0';
      AQry_CSM.Open;
      Pb_Read.Position := 0;
      Pb_Read.Max := AQRY_Excel.RecordCount;
      lb_ExcelJD.Caption := '';
      Application.ProcessMessages;
      if Chb_ClearTable.Checked then
      begin
        SJBH := 1;
      end
      else
      begin
        SJBH := GetSIDInt(FACon, 'S_KH_YHTSHT', 'SJBH');
      end;
      AQRY_Excel.First;
      while not AQRY_Excel.Eof do
      begin
        lb_ExcelJD.Caption := IntToStr(AQRY_Excel.RecNo) + '/' + IntToStr(AQRY_Excel.RecordCount);
        Pb_Read.Position := AQRY_Excel.RecNo;
        Application.ProcessMessages;

        AQry_CSM.Append;

        AQry_CSM.FieldByName('SJBH').AsInteger := SJBH;
        SJBH := SJBH + 1;

        AQry_CSM.FieldByName('KHSH').AsString := AQRY_Excel.FieldByName('税号').AsString;
        AQry_CSM.FieldByName('KHMC').AsString := AQRY_Excel.FieldByName('名称').AsString;

        AQry_CSM.FieldByName('PYJM').AsString := UpperCase(HzSpell1.PyHeadOfHz(AQRY_Excel.FieldByName('名称').AsString));

       // AQry_CSM.FieldByName('BZ').AsString := AQRY_Excel.FieldByName('备注').AsString;

        AQry_CSM.Post;

        AQRY_Excel.Next;
      end;
      FACon.CommitTrans;
      Application.ProcessMessages;

    except
      on E: Exception do
      begin
        FACon.RollbackTrans;
        MsgBoxS('行(' + IntToStr(AQRY_Excel.RecNo) + ')读取错误:' + E.message);
        Exit;
      end;
    end;

    Application.ProcessMessages;

    DB_ZDSZ_Load(FACon, 'S_KH_YHTSHT_DRRead', DBGrd_CSM, AQRY_CSM);
    self.PGC_Main.ActivePageIndex := 1;
  finally
    AQRY_Excel.EnableControls;
  end;
end;

procedure TF_S_KH_DR.Act_1_PExecute(Sender: TObject);
begin
  FSJOK := False;
  self.PGC_Main.ActivePageIndex := 0;
end;

procedure TF_S_KH_DR.Act_1_NExecute(Sender: TObject);
var
  RQSJT: TDateTime;

  YWGUID: string;
begin
  Self.Mem_JCTS.Clear;
  self.PGC_Main.ActivePageIndex := 2;
  Application.ProcessMessages;

  PB_JD.Max := AQry_CSM.RecordCount;
  PB_JD.Position := 0;


  RQSJT := Now; //GetFWQSJ(FACon);
  //YWGUID := GetGuid;
  FACon.BeginTrans;
  try
    if Chb_ClearTable.Checked then
    begin
      AQry_DRCmd.Close;
      AQry_DRCmd.Connection := FACon;
      AQry_DRCmd.SQL.Text := 'Delete FROM  S_KH_YHTSHT';


      AQry_DRCmd.ExecSQL;
      AQry_DRCmd.Close;
    end;
    self.Mem_JCTS.Lines.Add('导入');
    AQry_DRM.Close;
    AQry_DRM.Connection := FACon;
    AQry_DRM.SQL.Text := 'SELECT * FROM S_KH_YHTSHT WHERE 1=0 ';
    AQry_DRM.Open;
    AQry_CSM.First;
    while not AQry_CSM.Eof do
    begin
      PB_JD.Position := AQry_CSM.RecNo;
      lbl_JD.Caption := IntToStr(AQry_CSM.RecNo) + '/' + IntToStr(AQry_CSM.RecordCount);
      Application.ProcessMessages;
      self.Mem_JCTS.Lines.Add(IntToStr(AQry_CSM.RecNo) + ' '
        + AQry_DRM.FieldByName('SJBH').AsString + ' ' + AQry_CSM.FieldByName('KHMC').AsString);

      AQry_DRM.Append;
     // AQry_DRM.FieldByName('YWGUID').AsString := YWGUID;
     // AQry_DRM.FieldByName('DRR').AsString := PCZYMC;

      AQry_DRM.FieldByName('SJBH').AsInteger := AQry_CSM.FieldByName('SJBH').AsInteger;
      YWGUID := '';
      YWGUID := GetGuid;
      AQry_DRM.FieldByName('YWGUID').AsString := YWGUID;

      AQry_DRM.FieldByName('KHSH').AsString := AQry_CSM.FieldByName('KHSH').AsString;
      AQry_DRM.FieldByName('KHMC').AsString := AQry_CSM.FieldByName('KHMC').AsString;
      AQry_DRM.FieldByName('PYJM').AsString := AQry_CSM.FieldByName('PYJM').AsString;



      AQry_DRM.FieldByName('DRRQ').AsDateTime := RQSJT;
      AQry_DRM.FieldByName('XGRQ').AsDateTime := RQSJT;
      AQry_DRM.FieldByName('TBRQ').AsDateTime := RQSJT;

      AQry_DRM.Post;

      AQry_CSM.Next;
    end;
    AQry_DRM.Close;
    FACon.CommitTrans;
    MsgBoxI('完成.');

  except
    on E: Exception do
    begin
      FACon.RollbackTrans;
      MsgBoxS('出错' + E.message);
    end;
  end;
end;

procedure TF_S_KH_DR.Act_2_PExecute(Sender: TObject);
begin
  self.PGC_Main.ActivePageIndex := 1;
end;

procedure TF_S_KH_DR.Act_2_NExecute(Sender: TObject);
begin
  Close;
  //self.PGC_Main.ActivePageIndex := 3;
end;

procedure TF_S_KH_DR.Act_3_PExecute(Sender: TObject);
begin
  self.PGC_Main.ActivePageIndex := 2;
end;

procedure TF_S_KH_DR.Act_3_NExecute(Sender: TObject);
begin

  Close;
  // self.PGC_Main.ActivePageIndex := 3;
end;

procedure TF_S_KH_DR.Act_DCExcel_AQryCSMExecute(Sender: TObject);
begin
  F_S_DB_DC_DataSetToExcel(AQry_CSM);
end;

procedure TF_S_KH_DR.Act_GridConfig_AQryCSMExecute(
  Sender: TObject);
begin
 //
  F_S_DB_ZDSZ_Show(FACON, 'S_KH_YHTSHT_DRRead', DBGrd_CSM, AQry_CSM);

end;

end.


窗体


object F_S_KH_DR: TF_S_KH_DR
  Left = 455
  Top = 125
  Width = 695
  Height = 651
  Caption = #32534#30721#23548#20837
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = #23435#20307
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 15
  object PGC_Main: TRzPageControl
    Left = 0
    Top = 0
    Width = 687
    Height = 613
    ActivePage = Tab1
    Align = alClient
    ShowFullFrame = False
    ShowShadow = False
    TabIndex = 1
    TabOrder = 0
    FixedDimension = 21
    object Tab0: TRzTabSheet
      Caption = 'Tab0'
      object Pnl_0_Head: TPanel
        Left = 0
        Top = 541
        Width = 687
        Height = 50
        Align = alBottom
        TabOrder = 0
        DesignSize = (
          687
          50)
        object lb_ExcelJD: TLabel
          Left = 283
          Top = 15
          Width = 40
          Height = 15
          Caption = 'Excel'
        end
        object Button2: TButton
          Left = 396
          Top = 10
          Width = 75
          Height = 25
          Anchors = [akTop, akRight]
          Caption = #19978#19968#27493
          Enabled = False
          TabOrder = 0
        end
        object Button3: TButton
          Left = 490
          Top = 10
          Width = 75
          Height = 25
          Action = Act_0_N
          Anchors = [akTop, akRight]
          TabOrder = 1
        end
        object Btn_0_Close: TButton
          Left = 584
          Top = 10
          Width = 75
          Height = 25
          Action = Act_Exit
          Anchors = [akTop, akRight]
          TabOrder = 2
        end
        object stat_1: TStatusBar
          Left = 106
          Top = 11
          Width = 135
          Height = 25
          Align = alNone
          Panels = <
            item
              Width = 50
            end>
        end
        object DBNavPlus2: TDBNavPlus
          Left = 1
          Top = 10
          Width = 100
          Height = 26
          DataSource = Ds_1
          VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
          TabOrder = 4
          Captions.Strings = (
            #26368#21069
            #21521#21069
            #21521#21518
            #26368#21518
            #25554#20837
            #21024#38500
            #32534#36753
            #25552#20132
            #25764#28040
            #21047#26032)
          CaptionsShow = False
          Spacing = 5
          Margin = -1
        end
      end
      object Panel1: TPanel
        Left = 0
        Top = 0
        Width = 687
        Height = 125
        Align = alTop
        TabOrder = 1
        DesignSize = (
          687
          125)
        object lbl_1: TLabel
          Left = 106
          Top = 41
          Width = 45
          Height = 15
          Caption = #24037#20316#34920
        end
        object Label1: TLabel
          Left = 14
          Top = 12
          Width = 51
          Height = 16
          Caption = #31532#19968#27493
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -16
          Font.Name = #23435#20307
          Font.Style = [fsBold]
          ParentFont = False
        end
        object Label8: TLabel
          Left = 83
          Top = 13
          Width = 70
          Height = 15
          Caption = 'Excel'#25991#20214
        end
        object Edt_ExcelFileName: TRzButtonEdit
          Left = 161
          Top = 10
          Width = 505
          Height = 23
          Anchors = [akLeft, akTop, akRight]
          Color = clInfoBk
          ReadOnly = True
          TabOrder = 0
          AltBtnKind = bkFind
          ButtonKind = bkFind
          HideButtonsOnReadOnly = False
          OnButtonClick = Edt_ExcelFileNameButtonClick
        end
        object cbb_ExcelGZB: TRzComboBox
          Left = 161
          Top = 37
          Width = 287
          Height = 23
          Style = csDropDownList
          ItemHeight = 0
          TabOrder = 1
          OnChange = cbb_ExcelGZBChange
        end
        object Chb_SY2003FS: TCheckBox
          Left = 161
          Top = 66
          Width = 288
          Height = 17
          Caption = #20351#29992'Excel2003'#29256#26041#24335
          TabOrder = 2
        end
        object Chb_ClearTable: TCheckBox
          Left = 162
          Top = 90
          Width = 502
          Height = 17
          Caption = #28165#31354#21407#34920#26723#26696#25152#26377#25968#25454'-'#21024#38500#24050#24405#20837#25152#26377#21512#21516#25968#25454
          TabOrder = 3
        end
      end
      object dbgrd_1: TDBGrid
        Left = 0
        Top = 125
        Width = 687
        Height = 397
        Align = alClient
        DataSource = Ds_1
        ReadOnly = True
        TabOrder = 2
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -15
        TitleFont.Name = #23435#20307
        TitleFont.Style = []
      end
      object Pb_Read: TProgressBar
        Left = 0
        Top = 522
        Width = 687
        Height = 19
        Align = alBottom
        TabOrder = 3
      end
    end
    object Tab1: TRzTabSheet
      Caption = 'Tab1'
      object Panel2: TPanel
        Left = 0
        Top = 0
        Width = 687
        Height = 41
        Align = alTop
        TabOrder = 0
        object Label3: TLabel
          Left = 14
          Top = 12
          Width = 51
          Height = 16
          Caption = #31532#20108#27493
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -16
          Font.Name = #23435#20307
          Font.Style = [fsBold]
          ParentFont = False
        end
        object Label2: TLabel
          Left = 77
          Top = 12
          Width = 90
          Height = 15
          Caption = #35835#21462#25968#25454#39044#35272
        end
      end
      object Panel5: TPanel
        Left = 0
        Top = 541
        Width = 687
        Height = 50
        Align = alBottom
        TabOrder = 1
        DesignSize = (
          687
          50)
        object Button1: TButton
          Left = 396
          Top = 10
          Width = 75
          Height = 25
          Action = Act_1_P
          Anchors = [akTop, akRight]
          TabOrder = 0
        end
        object Button4: TButton
          Left = 490
          Top = 10
          Width = 75
          Height = 25
          Action = Act_1_N
          Anchors = [akTop, akRight]
          TabOrder = 1
        end
        object Button5: TButton
          Left = 584
          Top = 10
          Width = 75
          Height = 25
          Action = Act_Exit
          Anchors = [akTop, akRight]
          TabOrder = 2
        end
        object Button12: TButton
          Left = 131
          Top = 10
          Width = 158
          Height = 26
          Action = Act_DCExcel_AQryCSM
          TabOrder = 3
        end
        object DBNavPlus1: TDBNavPlus
          Left = 16
          Top = 10
          Width = 100
          Height = 26
          DataSource = Ds_CSM
          VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
          TabOrder = 4
          Captions.Strings = (
            #26368#21069
            #21521#21069
            #21521#21518
            #26368#21518
            #25554#20837
            #21024#38500
            #32534#36753
            #25552#20132
            #25764#28040
            #21047#26032)
          CaptionsShow = False
          Spacing = 5
          Margin = -1
        end
      end
      object DBGrd_CSM: TDBGridEh
        Left = 0
        Top = 41
        Width = 687
        Height = 500
        Align = alClient
        DataSource = Ds_CSM
        DynProps = <>
        Flat = True
        IndicatorOptions = [gioShowRowIndicatorEh, gioShowRecNoEh]
        Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit]
        OptionsEh = [dghFixed3D, dghHighlightFocus, dghClearSelection, dghDialogFind, dghShowRecNo, dghColumnResize, dghColumnMove, dghExtendVertLines]
        PopupMenu = PM_Grid
        TabOrder = 2
        TitleParams.MultiTitle = True
        object RowDetailData: TRowDetailPanelControlEh
        end
      end
    end
    object Tab2: TRzTabSheet
      Caption = 'Tab2'
      object Panel3: TPanel
        Left = 0
        Top = 0
        Width = 687
        Height = 41
        Align = alTop
        TabOrder = 0
        object Label5: TLabel
          Left = 14
          Top = 12
          Width = 51
          Height = 16
          Caption = #31532#19977#27493
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -16
          Font.Name = #23435#20307
          Font.Style = [fsBold]
          ParentFont = False
        end
        object Label4: TLabel
          Left = 77
          Top = 12
          Width = 150
          Height = 15
          Caption = #25968#25454#26657#39564#24182#20889#20837#25968#25454#24211
        end
      end
      object Panel6: TPanel
        Left = 0
        Top = 541
        Width = 687
        Height = 50
        Align = alBottom
        TabOrder = 1
        DesignSize = (
          687
          50)
        object Button6: TButton
          Left = 396
          Top = 10
          Width = 75
          Height = 25
          Action = Act_2_P
          Anchors = [akTop, akRight]
          TabOrder = 0
        end
        object Button7: TButton
          Left = 490
          Top = 10
          Width = 75
          Height = 25
          Action = Act_2_N
          Anchors = [akTop, akRight]
          TabOrder = 1
        end
        object Button8: TButton
          Left = 584
          Top = 10
          Width = 75
          Height = 25
          Action = Act_Exit
          Anchors = [akTop, akRight]
          TabOrder = 2
        end
      end
      object Panel8: TPanel
        Left = 0
        Top = 434
        Width = 687
        Height = 30
        Align = alBottom
        Caption = 'Panel8'
        TabOrder = 2
        object PB_JD: TProgressBar
          Left = 1
          Top = 1
          Width = 685
          Height = 28
          Align = alClient
          TabOrder = 0
        end
      end
      object Mem_JCTS: TMemo
        Left = 0
        Top = 41
        Width = 687
        Height = 393
        Align = alClient
        Lines.Strings = (
          'Mem_JCTS')
        TabOrder = 3
      end
      object Panel9: TPanel
        Left = 0
        Top = 464
        Width = 687
        Height = 77
        Align = alBottom
        BevelOuter = bvNone
        TabOrder = 4
        object Label6: TLabel
          Left = 16
          Top = 15
          Width = 191
          Height = 15
          Caption = #27491#22312#22788#29702#25968#25454','#35831#38144#20505'......'
        end
        object lbl_JD: TLabel
          Left = 16
          Top = 42
          Width = 191
          Height = 15
          Caption = #27491#22312#22788#29702#25968#25454','#35831#38144#20505'......'
        end
      end
    end
    object Tab3: TRzTabSheet
      Caption = 'Tab3'
      object Panel4: TPanel
        Left = 0
        Top = 0
        Width = 687
        Height = 41
        Align = alTop
        TabOrder = 0
        object Label7: TLabel
          Left = 14
          Top = 12
          Width = 51
          Height = 16
          Caption = #31532#22235#27493
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -16
          Font.Name = #23435#20307
          Font.Style = [fsBold]
          ParentFont = False
        end
      end
      object Panel7: TPanel
        Left = 0
        Top = 541
        Width = 687
        Height = 50
        Align = alBottom
        TabOrder = 1
        DesignSize = (
          687
          50)
        object Button9: TButton
          Left = 396
          Top = 10
          Width = 75
          Height = 25
          Anchors = [akTop, akRight]
          Caption = #19978#19968#27493
          TabOrder = 0
        end
        object Button10: TButton
          Left = 490
          Top = 10
          Width = 75
          Height = 25
          Anchors = [akTop, akRight]
          Caption = #19979#19968#27493
          Enabled = False
          TabOrder = 1
        end
        object Button11: TButton
          Left = 584
          Top = 10
          Width = 75
          Height = 25
          Action = Act_Exit
          Anchors = [akTop, akRight]
          TabOrder = 2
        end
      end
    end
  end
  object AQry_CSM: TADOQuery
    LockType = ltBatchOptimistic
    Parameters = <>
    Left = 145
    Top = 184
  end
  object Ds_CSM: TDataSource
    DataSet = AQry_CSM
    Left = 142
    Top = 249
  end
  object ActionList1: TActionList
    Left = 148
    Top = 119
    object Act_Exit: TAction
      Caption = #20851#38381
      OnExecute = Act_ExitExecute
    end
    object Act_0_N: TAction
      Caption = #19979#19968#27493
      OnExecute = Act_0_NExecute
    end
    object Act_1_P: TAction
      Caption = #19978#19968#27493
      OnExecute = Act_1_PExecute
    end
    object Act_1_N: TAction
      Caption = #19979#19968#27493
      OnExecute = Act_1_NExecute
    end
    object Act_2_P: TAction
      Caption = #19978#19968#27493
      OnExecute = Act_2_PExecute
    end
    object Act_2_N: TAction
      Caption = #23436#25104
      OnExecute = Act_2_NExecute
    end
    object Act_3_P: TAction
      Caption = #19978#19968#27493
      OnExecute = Act_3_PExecute
    end
    object Act_3_N: TAction
      Caption = #19979#19968#27493
      OnExecute = Act_3_NExecute
    end
    object Act_GridConfig_AQryCSM: TAction
      Caption = #34920#26684#35774#32622
      OnExecute = Act_GridConfig_AQryCSMExecute
    end
    object Act_DCExcel_AQryCSM: TAction
      Caption = #23548#20986#39044#35272#25968#25454
      OnExecute = Act_DCExcel_AQryCSMExecute
    end
  end
  object PM_Grid: TPopupMenu
    Left = 305
    Top = 214
    object N1: TMenuItem
      Action = Act_GridConfig_AQryCSM
    end
  end
  object AQry_DRM: TADOQuery
    Parameters = <>
    Left = 222
    Top = 129
  end
  object AQry_Tmp: TADOQuery
    Parameters = <>
    Left = 140
    Top = 326
  end
  object AQry_XZ: TADOQuery
    LockType = ltBatchOptimistic
    Parameters = <>
    Left = 224
    Top = 312
  end
  object Ds_1: TDataSource
    DataSet = AQRY_Excel
    OnStateChange = Ds_1StateChange
    OnDataChange = Ds_1DataChange
    OnUpdateData = Ds_1UpdateData
    Left = 38
    Top = 247
  end
  object ACON_DBE: TADOConnection
    LoginPrompt = False
    Left = 46
    Top = 119
  end
  object AQRY_Excel: TADOQuery
    Connection = ACON_DBE
    Parameters = <>
    Left = 41
    Top = 180
  end
  object AQry_DRCMD: TADOQuery
    Parameters = <>
    Left = 231
    Top = 212
  end
  object HzSpell1: THzSpell
    Left = 407
    Top = 98
  end
end



利用ado将excel数据直接导入数据库

从软件工程的角度来说,我的工作很多是把次序掉转了过来,因为我是在开发工作的中后期才将文档写出来,往往也只是个数据流、工作流和一些功能需求的总结记录,算不上完整的开发文档。从头到尾都是一个人干,这就不存...
  • verious
  • verious
  • 2007年06月26日 09:42
  • 1366

自我保留-SQL操作EXCEL时HDR和IMEX的实际效果

  • dn98201
  • dn98201
  • 2015年08月13日 17:12
  • 229

delphi 用ado连接excel2007

前段时间写了一个用delphi比较两个excel不同的程序。使用了ado ,但是发现怎么都连接不上。最后知道原因了。我使用的office是2007版本的。原因是office2007已经是基于xml的。...
  • kobaer
  • kobaer
  • 2009年10月11日 12:39
  • 3893

利用ADO操作Excel文件

今天花时间研究了一下ADO操作Excel文件的问题,跟大家分享一下:首先利用Excel2003创建了一个名为Demo.xls的文件,内容如下: N...
  • tabby
  • tabby
  • 2007年11月16日 22:50
  • 12440

ADO读取Excel的简单例子

一、简单说明: 工程名字ADO_Excel,类型是console app, 非empty有预编译头stdafx.h。 编译说明: 1.确保C盘下面路径有msado15.dll,没有安装office2...
  • Blues1021
  • Blues1021
  • 2015年02月04日 12:14
  • 6199

VB通过ADO快速读取EXCEL与TXT文件

该方法读取30*50格的EXCEL数据仅需要1秒钟,比使用CELLS属性一个个读取快了将近100倍。但是使用该方法读取程序自动生成的EXCEL文件时会出现如下错误提示:外部表不是预期的格式。据查是因为...
  • changleqy
  • changleqy
  • 2007年07月31日 09:37
  • 7476

ADO读取Excel内容

最近用到excel导入数据库的问题,网上查阅资料之后整理出相对独立的一个版本,以便于以后使用。 这里创建一个基于VS2005的控制台应用程序,字符集设置为“未设置”,经测试可以通过,有关ADO操作E...
  • pigautumn
  • pigautumn
  • 2013年05月29日 16:52
  • 2322

delehi使用Ado方式读取EXCEL导入的Demo

delehi使用Ado方式读取EXCEL导入的Demo 源码 unit UF_S_KH_DR; interface uses   Windows, Messages, Sys...
  • lichina
  • lichina
  • 2015年11月20日 17:32
  • 545

ADO访问Excel 2007

1、数据引擎类型    有两种接口可供选择:Microsoft.Jet.OLEDB.4.0(简称 Jet 引擎)和Microsoft.ACE.OLEDB.12.0(简称 ACE 引擎)。    Jet...
  • fhfanxin
  • fhfanxin
  • 2016年03月04日 22:40
  • 1702

VBA中使用ADO来处理Excel数据之现状

VBA中使用ADO来处理Excel数据之现状 Excel工作表中的行和列与数据库中的行和列非常相似。ADO 让我们可以将 Excel 工作簿看做和数据库一样,用ADO的好处是可以不通过OPEN...
  • gxsky
  • gxsky
  • 2017年07月02日 11:57
  • 428
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:delehi使用Ado方式读取EXCEL导入的Demo
举报原因:
原因补充:

(最多只允许输入30个字)