我用Delphi 7.0开发,采用ACCESS数据库,现在在做一个导入功能 ,把ACCESS数据库里的数据导出至EXCEL里。不知怎么办?

解决方案 »

  1.   

    呵呵,写个程序,在excel中把它指定字段,在把字段一个个的insert into到数据库中,就可以了,!
      

  2.   

    unit Unit1;interfaceuses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, DBGrids, ExtCtrls, DBTables,
        Excel2000, OleServer, ComObj, ComCtrls, Registry;type
        TForm1 = class(TForm)
            GroupBox1: TGroupBox;
            PB: TProgressBar;
            OD: TOpenDialog;
            DataSource2: TDataSource;
            SG: TStringGrid;
            sb: TSpeedButton;
            CB: TCheckBox;
            DBG: TDBGrid;
            procedure sbClick(Sender: TObject);
            procedure FormClose(Sender: TObject; var Action: TCloseAction);
        private
            { Private declarations }
        public
            { Public declarations }
        end;var
        Form1: TForm1;
        eclApp, WorkBook: Variant;
        Sheet, Cell: Variant;
        m, n: integer; //m列n行;
        //SG.cells[列,行]
        //Sheet.cells[行,列]implementation{$R *.dfm}procedure TForm1.sbClick(Sender: TObject);
    var
        I, j: integer;
    begin
        OD.InitialDir := ExtractFilePath(Application.ExeName);
        if OD.Execute then begin
            SG.DefaultDrawing := false;
            try
                eclApp := CreateOleObject('Excel.Application');
                WorkBook := CreateOleObject('Excel.sheet');
                WorkBook := eclApp.workbooks.open(OD.filename);
                Sheet := eclApp.activesheet;
                //取得列数
                for I := 1 to Sheet.columns.count do begin
                    if Length(Trim(Sheet.cells[1, I])) = 0 then begin
                        m := I;
                        break;
                    end;
                end;            //取得行数
                for j := 1 to Sheet.columns.rows.count do begin
                    if Length(Trim(Sheet.cells[j, 1])) = 0 then begin
                        n := j;
                        break;
                    end;
                end;
                SG.ColCount := m - 1; //m=17
                SG.RowCount := n - 1; //n=1946
                {F_select.LB_source.Clear;
                for I := 1 to m do begin
                    F_select.LB_source.Items.Add(Sheet.cells[1, I].value);
                    SG.cells[I - 1, 0] := Sheet.cells[1, I].value;
                end;}
                CB.Checked := True;        except
                sb.Down := false;
                CB.Checked := false;
                SG.RowCount := 0;
                SG.ColCount := 0;
                SG.cells[0, 0] := '';
                eclApp.Quit;
                eclApp := Unassigned;
                showmessage('打开Excel文件失败');
                exit;
            end;
            SG.DefaultDrawing := True;
        end
        else begin
            sb.Down := false;
            CB.Checked := false;
            SG.RowCount := 0;
            SG.ColCount := 0;
            SG.cells[0, 0] := '';
        end;end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
        try
            eclApp.Quit;
            eclApp := Unassigned;
        except
        end;
    end;end.我想这样,你应该明白了吧!!!!!!  自己按照我的程序做一便就好了! 应该还好!