把表的数据导出到EXCEL,同时还可以打印
2007-02-08 15:00
309 查看
以下代码出自http://blog.csdn.net/hellogv/,引用请注明出处!
首先加入这两句:
#include "utilcls.h"
#include "comobj.hpp"
下面正式开始:
首先加入这两句:
#include "utilcls.h"
#include "comobj.hpp"
下面正式开始:
void __fastcall TMainForm::ToExcel(TADOQuery *TT,AnsiString str) {//TT为被导出数据的表,str为命令(具体看代码底部的if语句) #define PG OlePropertyGet #define PS OlePropertySet #define FN OleFunction #define PR OleProcedure Variant excel; try { excel=CreateOleObject("Excel.Application"); //启动Excel } catch(...) { ShowMessage("无法启动Excel,请检查是否已经安装EXCEL!"); } excel.PS("Visible", (Variant)true); //使Excel启动后可见 excel.PG("workbooks").FN("Add", 1); //单工作表 for(int i=0;i<TT->FieldCount;i++) //首先给EXCEL添加表的字段名 { excel.Exec(PropertyGet("Cells")<<1<<i+1).Exec(PropertySet("Value")<<TT->FieldList->Strings[i]); } for(int j=0;j<TT->FieldCount;j++)//按字段排列 { TT->First(); for(int i=0;i<TT->RecordCount;i++)//按数据顺序排雷 { excel.Exec(PropertyGet("Cells")<<i+2<<j+1).Exec(PropertySet("Value")<<TT->FieldByName(TT->FieldList->Strings[j])->AsString); TT->Next(); } } if(str=="导出"){}//如果是导出,就什么都不干 if(str=="打印")//如果是打印 excel.OlePropertyGet("ActiveWorkBook").OlePropertyGet("ActiveSheet").OleFunction("PrintOut"); if(str=="打印浏览")//如果是打印浏览 excel.OlePropertyGet("ActiveWorkBook").OlePropertyGet("ActiveSheet").OleFunction("PrintPreview"); excel.~Variant(); } //---------------------------------------------------------------------------
相关文章推荐
- 把表的数据导出到EXCEL,同时还可以打印
- C++中实现把表的数据导出到EXCEL并打印实例代码
- Java大批量导出数据,格式可以为xml或excel
- PB中将数据导出到Word或Excel后,不打开文件直接打印
- 实现GridView中的数据的打印和导出到Excel
- java使用poi导出excel的内容,同时可以利用反射进行动态获取信息
- 将数据导出为Excel或Word格式,以及打印方法
- 实现GridView中的数据的打印和导出到Excel
- 怎么把数据导出到excel,提供打印。
- oms数据通过excel模板导出excel文件,同时可在excel模板中添加计算公式
- Java大批量导出数据,格式可以为xml或excel.
- asp生成和导出excel和word数据源码和代码,简单好用(已经测试可以用)
- pdf图表导出总结,同时可以应用到excel中
- winform DataGridView导出数据到Excel中,可以导出当前页和全部数据
- 如果通过toad得到表结构的sql语句?通过toad可以导入导出excel数据文件吗?
- Java大批量导出数据,格式可以为xml或excel
- java中使用poi导出excel表格数据并且可以手动修改导出路径
- 转:现在您可以随意的将datagridView中的数据导出到Excel中了(仍然保留你在datagridView中的排序格式),加注释的哦
- asp生成和导出excel和word数据源码和代码,简单好用(已经测试可以用)
- c# winform DataGridView导出数据到Excel中,可以导出当前页和全部数据