dbgrid 如何導入Word呢(100分)

  • 主题发起人 主题发起人 goddy
  • 开始时间 开始时间
G

goddy

Unregistered / Unconfirmed
GUEST, unregistred user!
dbgrid 如何導入Word呢
 
自己看看
http://www.delphibbs.com/delphibbs/dispq.asp?lid=737517
 
這個不行吧
 
自己写代码,有点麻烦而已
 
可以实现,我认为是一个能好的思路。我在paradox数据库实现,感觉很好。
将word的内容copy到剪切板,复制到数据库的感应控件。反操作即可将数据库的字段内容
copy到word文档,已发不少贴了
http://211.101.4.25/delphibbs/dispq.asp?lid=1092315
http://www.delphibbs.com/delphibbs/dispq.asp?LID=1037239
http://www.delphibbs.com/delphibbs/dispq.asp?LID=737517

 
写成html用word打开最简单,要不你就要写VBA了。啰嗦呀,啰嗦!
 
还是给你个现成的吧,我刚写的(D6+Word2000)
unit MyOffice2000;

interface

uses
DBGrids, ComObj, word2000, DB;

function DBGrid2Word(DBGrid:TDBGrid;Title:String):Boolean;

implementation

function DBGrid2Word(DBGrid:TDBGrid;Title:String):Boolean;
var
MSWord2000: OLEVariant;
ColCount,RowCount,I:Integer;
ColumnTitle,CellStr:String;
begin
Result:=False;
//打开Word2000;
try
MSWord2000 := GetActiveOleObject('Word.Application');
except
try
MSWord2000 := CreateOleObject('Word.Application');
except
Exit;
end;
end;
MSWord2000.Visible := True;
//创建空文档;
MSWord2000.Documents.Add();
//写入标题;
MSWord2000.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
MSWord2000.Selection.Font.Size:=22;
MSWord2000.Selection.Font.Bold:=wdToggle;
MSWord2000.Selection.TypeText(Text:=Title);
//MSWord2000.Selection.MoveRight(Unit:=1, Count:=1);
MSWord2000.Selection.TypeParagraph;
MSWord2000.Selection.ParagraphFormat.Alignment:= wdAlignParagraphJustify;
MSWord2000.Selection.Font.Size:=11;
MSWord2000.Selection.Font.Bold:=wdToggle;
MSWord2000.Selection.TypeParagraph;
with DBGrid.DataSource.DataSet do
begin
ColCount:=FieldCount;
RowCount:=RecordCount;
//画出空表格;
MSWord2000.ActiveDocument.Tables.Add(Range:=MSWord2000.Selection.Range,
NumRows:=RowCount+1,
NumColumns:=ColCount,
DefaultTableBehavior:=0,
AutoFitBehavior:=0);
//写入表格的表头
for I:=0 to ColCount-1 do
begin
MSWord2000.Selection.Font.Bold:= wdToggle;
MSWord2000.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
ColumnTitle:=DBGrid.Columns.Title.Caption;
//Fields.FieldName;
MSWord2000.Selection.TypeText(Text:=ColumnTitle);
if I<ColCount-1 then
MSWord2000.Selection.MoveRight(Unit:=wdCell);
end;
First;
//写入表格中的数据;
while not EOF do
begin
MSWord2000.Selection.MoveDown(Unit:=wdLine,Count:=1);
MSWord2000.Selection.MoveLeft(Unit:=wdCell,Count:=ColCount-1);
for I:=0 to ColCount-1 do
begin
CellStr:=Fields.AsString;
MSWord2000.Selection.TypeText(Text:=CellStr);
if I<ColCount-1 then
MSWord2000.Selection.MoveRight(Unit:=wdCell);
end;
Next;
end;
MSWord2000.Selection.MoveRight(Unit:=wdCharacter, Count:=1);
MSWord2000.Selection.InsertRows( 1);
MSWord2000.Selection.Collapse (Direction:=wdCollapseStart);
MSWord2000.Selection.TypeText (Text:='合计');
for I:=1 to ColCount-1 do
begin
MSWord2000.Selection.MoveRight(Unit:=wdCell, Count:=1);
if Fields.DataType in [ftSmallint,ftInteger,ftWord,ftFloat,ftCurrency] then
begin
MSWord2000.Selection.InsertFormula (Formula:='=SUM(ABOVE)', NumberFormat:='');
end;
end;
end;
Result:=True;
end;

end.

记得把分数给我
 
控件
www.51delphi.com
下载quickexport,可以导出到word,execl,html,txt.
 
接受答案了.
 
后退
顶部