控件名称 | 属性 | 值 | 说明 |
Tlabel1 | Caption | "请输入文件名" | |
TEdit1 | Name | "" | 用来输入文件名,带扩展名的 |
TButton1 | Caption | "保存" | |
TButton2 | Caption | "退出" | |
ADOTable1 | Active ConnectionString TableName | True PRovider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb;Persist Security Info=False userdata |
下面是相关代码:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant OLEObject;
AnsiString dataword;
if(Trim(Edit1->Text)=="")
{
ShowMessage("请输入文件名");
return;
}
String currentPath=GetCurrentDir()+"//"+Trim(Edit1->Text);
OLEObject=CreateOleObject("Word.Basic");
OLEObject.Exec(Procedure("FileNew"));
OLEObject.Exec(Procedure("EndOfDocument"));
ADOTable1->First();
while(ADOTable1->Eof!=True)
{
dataword=ADOTable1->FieldValues["工号"]+ADOTable1->FieldValues["姓名"]+ADOTable1->FieldValues["性别"]+ADOTable1->FieldValues["部门"];
OLEObject.Exec(Procedure("Insert")<<dataword);
ADOTable1->Next();
}
OLEObject.Exec(Procedure("StartOfDocument"));
OLEObject.Exec(Procedure("FileSaveAs")<<currentPath);
OLEObject.Exec(Procedure("FileClose")<<1);
ShowMessage("文件已经写入!谢谢使用!");
}
---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
this->Close();
}
---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Click(TObject *Sender)
{
Edit1->Text="";
}
新闻热点
疑难解答