用Delphi在word中插入表
一个输出到模板表格中的例子 uses SysUtils,Windows,ADODB,DB,Word97,OleServer, Classes; var sSQL: String; qry: TADOQuery; fileN:OLEvariant; oleGrid: array[1..5] of olevariant; oWordApp: TWordApplication; oWordDoc: TWordDocument; sResult: String; i: Integer; begin qry:= nil; try sResult:= ' '; with qry do begin qry:= TADOQuery.Create(nil); qry.LockType:= ltReadOnly; //转换日期范围 //加载合同项目数据 sSQL:= 'select ProjectName, ProjectCode from FPPro_Project where ProjectID= '+ IntToStr(iProjectID); db_uPublic_GetRecordset(gConn, sSQL, qry); if RecordCount= 0 then begin //如果没有记录,退出 qry.Free; Result:= '没有找到项目记录! '; Exit; end; //连接Word oWordApp:= TWordApplication.Create(nil); owordDoc:= TWordDocument.Create(nil); try oWordApp.Connect; except qry.Free; owordDoc.Free; oWordApp.Free; Result:= '你可能没有安装Word! '; Exit; end; fileN:= fucGetExePath+ 'Template\基础资料清单.dot '; if not FileExists(fileN) then begin Result:= '没有找到模板文件! '; Exit; end; oWordApp.Documents.Add(fileN,emptyparam); oWordDoc.ConnectTo(oWordApp.ActiveDocument as _document); oWordApp.Options.CheckSpellingAsYouType:= False; //关闭拼写检查 oWordApp.Options.CheckGrammarAsYouType:= False; //关闭语法检查 oleGrid[1]:= oWordDoc.Tables.Item(1); oleGrid[1].Cell(1,2).Range.Text:= FieldByName( 'ProjectName ').AsString; oleGrid[1].Cell(1,4).Range.Text:= FieldByName( 'ProjectCode ').AsString; sSQL:= 'select FileName, CreateLogon, CreateDate from (FPPro_AddonFile ' + 'left join FPPro_RFile on FPPro_AddonFile.FileID=FPPro_RFile.FileID) ' + 'where FPPro_AddonFile.FileType=2 and FPPro_RFile.RelationKind=1 ' + 'and FPPro_RFile.RID= '+ IntToStr(iProjectID); db_uPublic_GetRecordset(gConn, sSQL, qry); oleGrid[1].Cell(6,1).Range.Text:= '共计份数: '+ IntToStr(RecordCount)+ '份 '; if RecordCount> 0 then begin //添加统计项目 First; i:=4; while not Eof do begin oleGrid[1].Cell(i,1).Range.Select; oWordApp.Selection.Rows.Add(emptyparam); //插入空行 oleGrid[1].Cell(i,1).Range.Text:= FieldByName( 'FileName ').AsString; oleGrid[1].Cell(i,2).Range.Text:= FieldByName( 'CreateLogon ').AsString; oleGrid[1].Cell(i,3).Range.Text:= FieldByName( 'CreateDate ').AsString; i:=i+1; Next; end; end; oWordApp.Visible:= True; oWordApp.WindowState:= 1; oWordApp.Activate; end; qry.Free; oWordApp.Free; owordDoc.Free; Result:= sResult; except on e: Exception do begin qry.Free; if owordDoc nil then owordDoc.Free; if oWordApp nil then oWordApp.Free; Result:= e.Message; end; end; end;
求一使用delphi调用word的简单程序。
我不太理解你想要做什麽,不过我看了你的问题后也做了一个把memo中的纪录导入到word档的例子,你可以参考一下: 单元接口引用 comobj单元。
procedure TForm1.Button3Click(Sender: TObject); var Word : Variant; begin try Word := CreateOLEObject('Word.Application'); Word.Documents.Open(extractfilepath(Application.ExeName)+'\test.doc',false); Word.Visible := false; Word.ActiveDocument.Range(0, 0); Word.ActiveDocument.Range.InsertAfter(memo1.Lines.Text); Word.ActiveDocument.Range.InsertParagraphAfter; Word.ActiveDocument.Range.Font.Name := 'MS Sans Serif';//砞竚?砰 Word.ActiveDocument.Range.Font.Size := 24;//砞竚?砰??掜 Word.Quit; finally Word.Quit; end; end;
怎么样在 Delphi 中打开一个word文件
delphi 调用 word 打开一个文档,兼容性比较好的办法,是使用 oleObject 来调用本机安装的 word,示例代码如下:procedure TForm1.Button1Click(Sender: TObject);var MSWord: Variant;begin MSWord := CreateOLEObject('Word.Application');//连接Word MSWord.Documents.Open(FileName:='D:\Temp\temp.doc', ReadOnly:=True); //打开外部Word文档 MSWord.Visible := 1;//是否显示文件编辑 MSWord.ActiveDocument.Range(Start:=0, End:=0);//开始改变的启止位置 MSWord.ActiveDocument.Range.InsertAfter(Text:='myvc');//在Word中增加字符'myvc' MSWord.ActiveDocument.Range.InsertParagraphAfter; MSWord.ActiveDocument.Range.Font.Size := 72;//字体大小 MSWord.ActiveDocument.Range.Font.Name := 'Arial';//字体名称
如何提高delphi+Word写入数据速度
usesword2000, comobj;varMyWord, MyDoc :Variant; beginMyWord := CreateOleObject('Word.Application');MyDoc := CreateOleObject('Word.Document');MyWord.Visible := 1;MyDoc := MyWord.Documents.Open(FileName := 'C:\A.doc', ReadOnly:=False);//打开外部Word文档MyDoc.Tables.Item(表格序号).Cell(x, y).Range.Text := 'abcd';...end;
WORD 段落样式在哪里?
word的段落排版一般需要打开“段落”对话框进行设置(简单情况下也可以用标尺和格式工具栏上的按钮进行操作):打开“段落”对话框后,可以发现,主要包括对齐方式、缩进和间距这几项内容:对齐方式是指:左、右对齐或居中等段落对齐方式;缩进是指:把文档的左或右空出一定的距离、以及首行空出几个字符等;间距是指:行与行之间的距离,以及段与段之间的距离。
转载请注明出处51数据库 » delphi word 段落