文件名称:怎样把DBGrid的内容导出到Excel
文件大小:3KB
文件格式:TXT
更新时间:2018-11-04 05:36:02
C++builder
void __fastcall TPhoneForm::SelectButtonClick(TObject *Sender)
{
AnsiString StrDate, ExName;//存放日期用于sheet
AnsiString Datatem,phone1="拨号";//临时存放数据库的字段值
int i,j;
//查询所需的数据
PhoneADOQuery->Close();
PhoneADOQuery->Parameters->ParamByName("date1")->Value=PhoneMaskEdit1->Text;
PhoneADOQuery->Parameters->ParamByName("date2")->Value=PhoneMaskEdit2->Text;
PhoneADOQuery->Active=true;
//新建一个EXCEL
Ex = Variant::CreateObject("Excel.Application");
Ex.OlePropertyGet("workbooks").OleFunction("Add", 6);
Wb = Ex.OlePropertyGet("ActiveWorkBook");
Sh = Wb.OlePropertyGet("ActiveSheet");
Ex.OlePropertySet("Visible", true);
//给sheet以日期重命名,
StrDate=DateToStr(Date());
Sh.OlePropertySet("Name", StrDate.c_str());
//给EXCEL输入数据
for (j=0;j