如何获取数据集?

dudd 2003-08-23 10:46:49
我用StoredProc 返回了数据集,用DBGrid显示,数据源datasource的dataset是此存储过程,现在我想将DBGrid的数据保存到Excel中,这就需要数据集dataset了,但好像dataset不能只将此datasouce设置就行了,还需要设置commandtype、commandtext(存储过程名称等)等,那我不就是重复执行了两遍存储过程吗(显示一次、生成Excel一次)?各位大虾有和建议,告知小弟,不胜感激!
...全文
156 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dudd 2003-08-23
  • 打赏
  • 举报
回复
那问题是templistview的数据来源是什么?StoredProc、DataSouce?这是写excel文件的方法,我问的是数据集如何设置可以公用已产生的结果。
checkyvc6 2003-08-23
  • 打赏
  • 举报
回复
自己写代码一条一条加入Excel
例子如下:
if templistview = nil then
exit;
if templistview.Items.Count < 1 then
exit;
tempGauge.Progress := 0;
tempGauge.MinValue := 0;
tempGauge.MaxValue := (templistview.Items.Count - 1) *
(templistview.Columns.Count - 1) + 2;
ExcelApp := TExcelApplication.Create(nil);
if messagedlg('是否可视', mtconfirmation, [mbyes, mbno], 0) = mryes then
ExcelApp.Visible[0] := true //是否可视
else
ExcelApp.Visible[0] := false; //是否可视
ExcelApp.Connect;
tempGauge.Progress := tempGauge.Progress + 1;
LCID := GetUserDefaultLCID();
wkBook := ExcelApp.WorkBooks.Add(EmptyParam, LCID);
wkSheet := wkBook.Sheets[1] as _WorkSheet;
wkSheet.Activate(LCID);
for j := 0 to templistview.Columns.Count - 1 do
begin
//showmessage(templistview.Columns[j].Caption );
wksheet.Cells.Item[1, j + 1].Value := templistview.Columns[j].Caption;
{todo: 加上宽度的限定}
end;

//设置标题颜色
wksheet.Range[wksheet.Cells.Item[1, 1], wksheet.Cells.Item[1,
wksheet.Columns.Count]].Font.Color := clBlue;

//改变标题宽度
for j := 0 to templistview.Columns.Count - 1 do
begin
wksheet.Range[wksheet.Cells.Item[1, j+1],
wksheet.Cells.Item[wksheet.Rows.Count, j+1]].ColumnWidth :=
templistview.Column[j].Width div 5;
end;

tempGauge.Progress := tempGauge.Progress + 1;
for i := 0 to templistview.Items.Count - 1 do
begin
wksheet.Cells.Item[i + 2, 1].Value := templistview.Items[i].Caption;
for j := 0 to templistview.Columns.Count - 2 do
begin
//showmessage(templistview.Items[i].SubItems[j]);
wksheet.Cells.Item[i + 2, j + 2].Value :=
templistview.Items[i].SubItems[j];
tempGauge.Progress := tempGauge.Progress + 1;
end;
end;

2,495

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧