1:怎样将cxGrid里的数据导入到EXCEL,HTML,XML和TEXT
uses
cxExportGrid4Link;
procedure TForm1.Button1Click(Sender: TObject);
begin
ExportGrid4ToEXCEL('d:/ddd/wang.xsl',cxGrid1,True,True);
ExportGrid4ToTEXT('d:/ddd/wang.txt',cxGrid1,True,True);
ExportGrid4ToXML('d:/ddd/wang.xml',cxGrid1,True,True);
ExportGrid4ToHTML('d:/ddd/wang.html',cxGrid1,True,True);
end;
2:让cxGrid显示数据
数据库连接:
procedure TForm1.FormCreate(Sender: TObject);
begin
try
//ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='''+SERVERPASS+''';Persist Security Info=True;User ID='''+SERVERNAME+''';Initial Catalog='''+SERVERDATA+''';Data Source='''+SERVERIP+'''';
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=books;Data Source=LXH';
ADOConnection1.Open;
except
Application.MessageBox('连接数据库失败!','提示',mb_ok+mb_iconinformation);
// Form1.Close;
end;
ADOQuery1.Connection:=ADOConnection1;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select * from jsb';
ADOQuery1.Open;
end;
把 cxGrid1Level1 和 cxGrid1DBTableView1 改名为:lvFilms 和 tvFilms,
从DataAccess页拖一个DataSource,把它的DataSet指向ADOQuery1
为tvFilms制定数据源
鼠标点击tvFilms 选DataController 的datasource指向DataSource 即可
然后 右击tvFilms