Delphi从DataSet导出到Excel
来源:互联网 发布:acronis备份软件 编辑:程序博客网 时间:2024/04/30 07:32
Delphi从DataSet导出到Excel
ExportDBGrid(toExcel: Boolean);
var
bm: TBookmark;
col, row: Integer;
sline: String;
mem: TMemo;
ExcelApp: Variant;
begin
Screen.Cursor := crHourglass;
form1.DBGrid1.DataSource.DataSet.DisableControls;
bm := form1.DBGrid1.DataSource.DataSet.GetBookmark;
form1.DBGrid1.DataSource.DataSet.First;
// create the Excel object
if toExcel then
begin
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.WorkBooks.Add(xlWBatWorkSheet);
ExcelApp.WorkBooks[1].WorkSheets[1].Name := 'Grid Data';
end;
// First we send the data to a memo
// works faster than doing it directly to Excel
mem := TMemo.Create(nil);
mem.Visible := false;
mem.Parent := form1;
mem.Clear;
sline := '';
// add the info for the column names
for col := 0 to form1.DBGrid1.FieldCount-1 do
sline := sline + form1.DBGrid1.Fields[col].DisplayLabel + #9;
mem.Lines.Add(sline);
// get the data into the memo
for row := 0 to form1.DBGrid1.DataSource.DataSet.RecordCount-1 do
begin
sline := '';
for col := 0 to form1.DBGrid1.FieldCount-1 do
sline := sline + form1.DBGrid1.Fields[col].AsString + #9;
mem.Lines.Add(sline);
form1.DBGrid1.DataSource.DataSet.Next;
end;
// we copy the data to the clipboard
mem.SelectAll;
mem.CopyToClipboard;
// if needed, send it to Excel
// if not, we already have it in the clipboard
if toExcel then
begin
ExcelApp.Workbooks[1].WorkSheets['Grid Data'].Paste;
ExcelApp.Visible := true;
end;
FreeAndNil(mem);
// FreeAndNil(ExcelApp);
form1.DBGrid1.DataSource.DataSet.GotoBookmark(bm);
form1.DBGrid1.DataSource.DataSet.FreeBookmark(bm);
form1.DBGrid1.DataSource.DataSet.EnableControls;
Screen.Cursor := crDefault;
end;
- Delphi从DataSet导出到Excel
- 从DataSet导出数据到excel!!
- Dataset导出到excel
- DataSet导出到Excel
- dataset 导出到 excel
- WinForm导出DataSet到Excel
- DataSet导出 到Excel 截取导出
- Excel编程之Dataset导出到excel
- delphi导出数据到excel
- DELPHI-----listview导出到excel
- CxGrid导出到Excel(Delphi)
- 将DataSet导出到Excel文件中
- 导出Dataset到Excel,并保持格式。
- 数据集DataSet导出到Excel
- GridView DataSet、Control 导出到 Excel
- 导出DataSet的数据到Excel中
- 数据库用DataSet导出到Excel
- 将DATASET中的内容导出到EXCEL
- 我在进步
- 网站制作 各大搜索引擎左侧第一页排名
- 转载:针对开发人员的 Windows SharePoint Services V3 和 SharePoint Server 2007 工作流简介
- Select的OnChange()事件
- 浅谈html中id和name的区别
- Delphi从DataSet导出到Excel
- 我blog最大的用处
- 数字日期转化为汉字日期格式...
- C#垃圾回收
- 【南京.NET聚会活动】4月26号榴园宾馆新华厅微软Visual Studio 2008新技术巡展
- linux上的输入法问题
- 组合模式
- Liferay研究之二十:如何防止连续重复提交
- java 创建xls文件实战