社区
Delphi
帖子详情
从不知道,如何用程序将数据导入一个Excel的文件里
zkfly
2001-09-16 11:05:40
例如:我从数据库中提取了一些数据,然后想把这些数据保存在一个Excel文件里,如何解决。请高手赐教。
...全文
113
2
打赏
收藏
从不知道,如何用程序将数据导入一个Excel的文件里
例如:我从数据库中提取了一些数据,然后想把这些数据保存在一个Excel文件里,如何解决。请高手赐教。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
tikkypeng
2001-09-16
打赏
举报
回复
看看下面代码~~研究研究~~
procedure DataToExcel(Grid:TDbGrid;DataSet:TDataset;Title:String;sExcelFile:String);
var
i,j,Row:integer;
WB: _WorkBook;
WBs: Workbooks;
FExcelWasFound:Boolean;
ExcelFile:string;
FileHandle: integer;
irange:range;
iWidth:integer;
//oFont:olevariant;
begin
try
Screen.Cursor :=crHourGlass ;
{for i:=0 to Grid.Columns.Count -1 do
begin
Dataset.Fields[i].DisplayWidth :=Grid.Columns[i].Width;
end; }
ExcelFile:=sExcelFile;
if not fileExists(ExcelFile) then
begin
FileHandle:=FileCreate(ExcelFile);
Fileclose(FileHandle);
end;
FExcelWasFound := True;
try
FApp := CreateOleObject('Excel.Application.9') as _Application; //调用Excel2000
except
FExcelWasFound := False;
end;
if not FExcelWasFound then //如果不存在,则调用Excel97
try
FApp := CreateOleObject('Excel.Application.8') as _Application;
FExcelWasFound := True;
except
FExcelWasFound := False;
ShowMessage('Excel调用失败!');
end;
if FExcelWasFound then
begin
InitVariables;
New(FSPms);
with FApp ,FSPms^ do
begin
App_SheetsInNewWorkbook := Get_SheetsInNewWorkbook(0);
App_DisplayFormulaBar := Get_DisplayFormulaBar(0);
App_ReferenceStyle := Get_ReferenceStyle(0);
App_DisplayStatusBar := Get_DisplayStatusBar(0);
Set_SheetsInNewWorkbook(0, 1);
WBs := Get_Workbooks; //打开Excel文件
WB := WBs.Open(excelFile, 3, false, 1,
'', '', True, $00000002, 1, False,
False, Null, False, 0);
MakeVBScript(WB); //初始化文件属性
end;
with FApp do
begin
Set_DisplayFormulaBar(0, False);
Set_ReferenceStyle(0, Integer(xlR1C1));
Set_DisplayStatusBar(0, False);
Set_Caption(Title);
end;
try
Row:=1;
irange:=Fapp.ActiveCell ;
irange.Font.Size :=9;
for j:=0 to Grid.FieldCount -1 do
begin
if Grid.Columns[j].Visible =true then
begin
if DataSet.Fields[j].displaywidth>254 then
iRange.ColumnWidth:=100
else
begin
//iWidth:=Grid.Columns[j].Width;
iRange.ColumnWidth :=Grid.Columns[j].Field.DisplayWidth ;
end;
irange.Font.Size :=9; //ljq 2001/03/09
irange.value:=Grid.Columns[j].Title.Caption ;
irange:=irange.Next;
end;
end;
except
ShowMessage('调用Excel出错!');
fApp._Release;
Screen.Cursor :=crDefault ;
exit;
end;
Row:=Row+2;
DataSet.DisableControls;
DataSet.First;
FApp.Get_ActiveWindow.DisplayZeros := True;
irange.NumberFormat:=10;
for i:=0 to DataSet.RecordCount -1 do
begin
irange:=Fapp.Range['A'+IntToStr(Row),'A'+intToStr(Row)];
for j:=0 to Grid.FieldCount -1 Do
begin
if Grid.Columns[j].Visible =True then
begin
if Grid<>nil then
begin
iRange.Font.Size :=Grid.Font.Size;
iRange.Font.Name :=Grid.Font.Name;
end
else
begin
irange.Font.Size :=FFontSize;
irange.Font.Name :=FFontName;
end; //edit by ljq 2001/03/09
iRange.Value :=Grid.Columns[j].Field.AsString ;
irange:=iRange.Next ;
end;
end;
DataSet.next;
Row:=Row+1;
end;
Screen.Cursor :=crDefault ;
DataSet.EnableControls;
irange:=FApp.Range['A1','K'+intToStr(Row-1)];
FApp.Set_Visible(0,True);
CreateToolBar(False); //屏蔽Excel的系统菜单,采用自定义菜单实现
end else
begin
ShowMessage('调用Excel2000或Excel97失败,请确认是否安装!'+#13#13+' 如果未安装,请先安装office');
Screen.Cursor :=crDefault ;
end;
except
ShowMessage('调用Excel出错!');
fApp._Release;
Screen.Cursor :=crDefault ;
exit;
end;
end;
tikkypeng
2001-09-16
打赏
举报
回复
循环~~根据数据库记录数量循环给Excel附值~~
破解RAR
WinRAR3.71正式版破解完美注册 Winrar这款软件想必大家都用过,但是也正是因为它是免费的,在试用期过了之后,我们每次使用都会出现提示注册的对话框.虽然,不影响软件的使用,但是每次使用的时候出现这个提示信息,想必会影响到你的心情. 1.新建
一个
文本
文件
(名字是"RarReg",扩展名是".txt"),将下面部分的内容复制到文本
文件
中. RAR regi...
winrar4.2注册RarReg.key
RAR registration data Federal Agency for Education 1000000 PC usage license UID=b621cca9a84bc5deffbf 6412612250ffbf533df6db2dfe8ccc3aae5362c06d54762105357d 5e3b1489e751c76bf6e0640001014be50a52303...
WINRAR RAG
RAR registration data
wncn
Unlimited Company License
UID=1b064ef8b57de3ae9b52
64122122509b52e35fd885373b214a4a64cc2fc1284b77ed14fa20
66ebfca6509f9813b32960fce6cb5ffde62890079861be57638717
7131ced835ed65cc743d9777f2ea71a8
winrar激活
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-02-11)新建记事本
文件
(txt
文件
),然后将
文件
另存为以 rarreg.key 为
文件
名的
文件
(当然由于设置的不同,可能出现你保存后的
文件
为 rarreg.key.txt 没关系,将其重命名,删掉.txt 会提示“改扩展名可能导致
文件
不可用”时点“确定”)然后在
里
面输入:====从==下==面==开==始==粘==贴==...
如何破解WinRAR
复制上方
数据
,新建个文本文档,把以上
数据
粘贴到文本文档中,保存
文件
名为 rarreg.key 的KEY
文件
即可,这样你就得到了
一个
授权
文件
,把授权
文件
复制到 Winrar 的安装根目录中,就成为注册版本了!
Delphi
5,943
社区成员
262,941
社区内容
发帖
与我相关
我的任务
Delphi
Delphi 开发及应用
复制链接
扫一扫
分享
社区描述
Delphi 开发及应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章