请教DBGrid的格式转换问题(100分)

  • 主题发起人 主题发起人 非常难
  • 开始时间 开始时间

非常难

Unregistered / Unconfirmed
GUEST, unregistred user!
请教大虾:DBGrid怎么转化成.TXT或者.XLS并保存,谢谢
 
我用的是bitbtn控件, 请在窗体上加上bitbtn,ttable,tdatabase,dbgrid
ExcelApplication,ExcelWorksheet, ExcelWorkbook1:控件
procedure TForm6.BitBtn1Click(Sender: TObject);
var i,row,column:integer;

begin

Try
ExcelApplication1.Connect;

Except
MessageDlg('Excel may not be installed',
mtError, [mbOk], 0);
Abort;
end;

ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
ExcelApplication1.Workbooks.Add(Null,0);
ExcelWorkbook1.ConnectTo
(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo
(ExcelWorkbook1.Worksheets[1] as _Worksheet);

Table1.Open;
row:=1;

While Not(Table1.Eof)do

begin

column:=1;

for i:=1 to Table1.FieldCountdo

begin

ExcelWorksheet1.Cells.Item[row,column]:=Table1.fields[i-1].AsString;
column:=column+1;

end;

Table1.Next;

row:=row+1;
end;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
end;

 
谢谢,我现在去试试看
 

Similar threads

后退
顶部