如何将Gride中的数据导入到。txt文件或者word中?(100分)

  • 主题发起人 主题发起人 fff2001
  • 开始时间 开始时间
F

fff2001

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把gride中的数据经过简单的运算后导入到。txt/doc文件中,该如何操作,
请经验人士加以指点
 
写程序跌代
 
谢谢老兄回复!我delphi并不是很熟,现在碰到问题不得不用delphi写,能说的详细点么!
 
我这里有代码可以直接写到EXCL中,你可以看看
PROCEDURE getdatefromdbintoexcel(dataset:tdataset;dbgrid:tdbgrid;title:string);
var i,row,column:integer;
X1:OLEVARIANT;
ASCCOLS:CHAR;
begin
Try
ExcelApplication1.Connect;
Except
MessageDlg('Excel 可能没有安装!',
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);
row:=1;
ExcelWorksheet1.Cells.Item[row,1]:=title;
//列的长度
ASCCOLS:=CHAR(dbgrid.Columns.Count+64);
ExcelWorksheet1.Range['A1',ASCCOLS+'1'].Merge(X1);
ExcelWorksheet1.Range['A1',ASCCOLS+'1'].HorizontalAlignment:=xlCenter;
row:=2;
// DATASET.FIRST;
// 设置单元格格式
for i:=1 to dataset.FieldCount do
begin
ASCCOLS:=CHAR(I+64);
if dataset.fields[i-1].DataType in [ftUnknown,ftstring] then
ExcelWorksheet1.Range[ASCCOLS+'3',ASCCOLS+INTTOSTR(3+dataset.RecordCount)].NumberFormatLocal:='@';
END;
ASCCOLS:=CHAR(dbgrid.Columns.Count+64);
for i:=0 to dbgrid.Columns.Count-1 do
ExcelWorksheet1.Cells.Item[row,i+1]:=dbgrid.Columns.Title.Caption;

row:=3;
While Not(dataset.Eof) do
begin
column:=1;
for i:=1 to dataset.FieldCount do
begin
ExcelWorksheet1.Cells.Item[row,column]:=dataset.fields[i-1].AsString;
column:=column+1;
end;
dataset.Next;
row:=row+1;
end;
//设置自动适应列宽
with ExcelWorksheet1.Range['A2',ASCCOLS+INTTOSTR(2+DATASET.RECORDCOUNT)] do
begin
Columns.AutoFit;
//设置边线
Borders.LineStyle:=xlcontinuous;
Borders.weight:=xlthin;
Borders.colorindex:=xlautomatic;
end;
//设置TITLE行高 AND FONTS
ExcelWorksheet1.Range['A1','A1'].RowHeight:=28;
ExcelWorksheet1.Cells.Item[1,1].FONT.NAME:='黑体';
ExcelWorksheet1.Cells.Item[1,1].FONT.size:=20;
ExcelWorksheet1.PageSetup.RightFooter:='&9第&P页 共&N页';
ExcelWorksheet1.PageSetup.PrintTitleRows:='$1:$2';
ExcelWorksheet1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelApplication1.Disconnect;

END;
 
谢谢了老兄
 
接受答案了.
 
后退
顶部