请问:数据库中的多级主从表导出到EXCEL怎么存储,并且可以再导入到数据库中!
谢谢,等待!!!!

解决方案 »

  1.   

    unit OfficeForm;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics,
      Controls, Forms, DBCtrls, StdCtrls, DBTables,
      ExtCtrls, Mask, Db, Dialogs, Excel97, Word97,
      OleServer;type
      TFormOff = class(TForm)
        DBEdit3: TDBEdit;
        Label3: TLabel;
        Label2: TLabel;
        DBEdit2: TDBEdit;
        DBEdit1: TDBEdit;
        Label1: TLabel;
        DBNavigator1: TDBNavigator;
        Table1: TTable;
        DataSource1: TDataSource;
        BtnExcel: TButton;
        SaveDialog1: TSaveDialog;
        ExcelApplication1: TExcelApplication;
        procedure BtnExcelClick(Sender: TObject);
      end;var
      FormOff: TFormOff;implementation{$R *.DFM}uses
      ComObj, ActiveX;
    procedure TFormOff.BtnExcelClick(Sender: TObject);
    var
      RangeE: Excel97.Range;
      I, Row: Integer;
      Book: TBookStr;
    begin
      // create and show
      ExcelApplication1.Visible [0] := True;
      ExcelApplication1.Workbooks.Add (NULL, 0);
      // fill is the first row with field titles
      RangeE := ExcelApplication1.ActiveCell;
      for I := 0 to Table1.Fields.Count - 1 do
      begin
        RangeE.Value := Table1.Fields [I].DisplayLabel;
        RangeE := RangeE.Next;
      end;
      // add field data in following rows
      Table1.DisableControls;
      try
        Book := Table1.Book;
        try
          Table1.First;
          Row := 2;
          while not Table1.EOF do
          begin
            RangeE := ExcelApplication1.Range ['A' + IntToStr (Row),
              'A' + IntToStr (Row)];
            for I := 0 to Table1.Fields.Count - 1 do
            begin
              RangeE.Value := Table1.Fields [I].AsString;
              RangeE := RangeE.Next;
            end;
            Table1.Next;
            Inc (Row);
          end;
        finally
          Table1.Book := Book;
        end;
      finally
        Table1.EnableControls;
      end;
      
      RangeE := ExcelApplication1.Range ['A1', 'E' + IntToStr (Row - 1)];
      RangeE.AutoFormat (3, NULL, NULL, NULL, NULL, NULL, NULL);
    end;initialization
      CoInitialize (nil);
    end.
      

  2.   

    http://expert.csdn.net/Expert/topic/2446/2446822.xml?temp=.2700312
    这个帖子看看,这几天关于EXCEL的问题很多。