我用StoredProc 返回了数据集,用DBGrid显示,数据源datasource的dataset是此存储过程,现在我想将DBGrid的数据保存到Excel中,这就需要数据集dataset了,但好像dataset不能只将此datasouce设置就行了,还需要设置commandtype、commandtext(存储过程名称等)等,那我不就是重复执行了两遍存储过程吗(显示一次、生成Excel一次)?各位大虾有和建议,告知小弟,不胜感激!
解决方案 »
- 线程问题请教
- .......................................................................................
- 修改数据这样对吗
- 如何正确拼QUERY的SQL语句串,确保引号匹配正确
- 网络传输问题
- 询问广州诚毅软件(立信企业下属单位)
- string,array[]of char,pchar 这三个类型的字符串怎么互相转换?
- 邮件的编码转换
- 判断一个条件的boolean值!bbtnApply.Enabled=true and (adoqrTech.State in [dsEdit,dsInsert])
- :Frame有何用途,与Form有何区别?
- Interbase有没有free的odbc driver
- 大家谈谈对OOP(面向对象化)的体会!
例子如下:
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;