- 中查找“数据库导出为XLS”更多相关内容
- 中查找“数据库导出为XLS”更多相关内容
- ·上一篇文章:DELPHI加注册表自启动的最简单代码
- ·下一篇文章:怎样制作登录窗体
数据库导出为XLS
DB,
ADODB,
StrUtils;
//filename是一个后带‘\’的目录
Function query1XLS(filename: String): boolean;
Var
cnn : TADOConnection;
query : tadoquery;
tablenames : tstrings;
filednames : tstrings;
i, j : integer;
XLS : tstrings;
s : String;
Begin
result := false;
cnn := TADOConnection.Create(form1);
cnn.ConnectionString := PromptDataSource(application.Handle, '''');
If cnn.ConnectionString = '''' Then exit;
cnn.CursorLocation := clUseServer;
cnn.LoginPrompt := false;
cnn.Connected := true;
tablenames := tstringlist.Create;
filednames := tstringlist.Create;
XLS := tstringlist.Create;
cnn.GetTableNames(tablenames);
Try
For i := 0 To tablenames.count - 1 Do
Begin
filednames.Clear;
cnn.GetFieldNames(tablenames.Strings[i], filednames);
Try
query := tadoquery.Create(form1);
query.Connection := cnn;
query.SQL.Clear;
query.SQL.Add(''select * from '' + tablenames.Strings[i]);
query.Open;
xls.Clear;
xls.Add(ansireplacetext(query.FieldList.Text, #13#10, #9));
s := '''';
For j := 0 To filednames.Count - 1 Do
s := s + query.Fields.Fields[j].AsString + #9;
xls.Add(s);
xls.SaveToFile(filename + tablenames.Strings[i] + ''.xls'');
Except
//
End;
End;
Finally
freeandnil(tablenames);
freeandnil(filednames);
freeandnil(xls);
result := true;
End;
End;
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论