请问怎么将Excel文件转换为dbase3格式!!急!!
请给个例子!!
谢谢
[email protected]

解决方案 »

  1.   

    下 面 的 例 子 展 示 了 从Foxpro 到SQL Server 的 数 据 转 移 方 法。 至 于 其 他 系 统 间 的 数 据 转 移, 只 要 根 据 目 标 系 统 的 数 据 定 义 要 求, 修 改 相 应 的Insert 语 句。 程 序 代 码 如 下: unit ConvertDBF;interfaceuses
     Windows, Messages, SysUtils, Classes,
     Graphics, Controls, Forms, Dialogs,
     StdCtrls, DBTables, Db, Grids, DBGrids;type
     TfrmConvertDB = class(TForm)
      btnOK: TButton;
      Label1: TLabel;
      db1: TDatabase;  {用于连接老数据库系统}
      db2: TDatabase;  {用于连接新数据库系统}
      dbg: TDBGrid; 
      tblSource: TTable; {dbg的Datasource}
    qryInsert: TQuery;
       {用于存放生成的SQL Insert语句}
      srcSource: TDataSource;
      tblDest: TTable; {DBGrid1的Datasource}
      DBGrid1: TDBGrid;
      srcDest: TDataSource;
      edFromtbl: TEdit;
      Label2: TLabel;
      Label3: TLabel;
      edToTbl: TEdit;
      procedure btnOKClick(Sender: TObject);
     private
      { Private declarations }
     public
      { Public declarations }
     end;var
     frmConvertDB: TfrmConvertDB;implementation{$R *.DFM}
    procedure TfrmConvertDB.btnOKClick
     (Sender: TObject);
    var iField :integer;
    begin
     if ((edTotbl.text<>’’) and 
     (edFromtbl.text<>’’))then begin
     tblSource.TableName:=edFromtbl.text; 
              {指定TableName}
     tblDest.TableName:=edTotbl.text;
     with tblSource do begin
       Open; {打开老系统的表}
       while EOF=FALSE do begin
           {逐条记录处理}
        qryInsert.SQL.Clear;
    qryInsert.sql.Add
    (’Insert into ’+edTotbl.text + ’(’);
        for iField:=0 to dbg.FieldCount-1 do begin
          qryInsert.sql.add
         (dbg.Fields[iField].DisplayLabel);
          if iField<>dbg.FieldCount-1 then
           qryInsert.sql.add(’,’);
        end;
        qryInsert.sql.add(’) values(’);
    for iField:=0 to dbg.FieldCount-1 do begin
        {进行数据类型转换}
          if dbg.fields[iField].DataType=ftInteger then
           qryInsert.sql.add(inttostr
          (dbg.fields[iField].asInteger));
          if dbg.fields[iField].DataType=ftFloat then
           qryInsert.sql.add(floattostr
          (dbg.fields[iField].asFloat));
          if dbg.fields[iField].DataType=ftDate then
           qryInsert.sql.add(’’’’+datetostr
          (dbg.fields[iField].asDateTime)+’’’’);
          if dbg.fields[iField].DataType=ftString then begin
           if dbg.fields[iField].asString<>’’ then
            qryInsert.sql.add(’’’’+dbg.fields
            [iField].asString+’’’’)
           else
            qryInsert.sql.add(’NULL’);
          end;
          if iField<>dbg.FieldCount-1
          then qryInsert.sql.add(’,’);
        end;
        qryInsert.sql.add(’)’);
    qryInsert.ExecSQL;
                  {把数据插入到新系统的表中}
        next;
       end;
     end;
     tblDest.Close;
     tblDest.Open;;
     ShowMessage(’  转换完毕!   ’);
     end
     else
      ShowMessage
      (’请输入要插入数据的表的名称   ’);
    end;
    end.