delphi逐行读取word文档 delphi 读取word文档
发布日期:2020-09-14摘要:delphi中怎么逐行读取文本文件的数据并分别写入指定的位置 FileName:string;f:Textfile;s:string;FileName:= C: this log ; AssignFi...
delphi中怎么逐行读取文本文件的数据并分别写入指定的位置
FileName:string;f:Textfile;s:string;FileName:="C:\this.log"; AssignFile(f,FileName);//关联文件Reset(f);Readln(f,s); //读一行memo1.Lines.Add(s); //写到MEMO1ReadLn(f,s); //再读一行memo2.Lines.Add(s);//写到MEMO2CloseFile(f);//关闭
delphi中把查询出来的数据导入word中?
我将我的商用《旅行社管理系统》的 发团通知 部分奉献给您,望对您有所帮助。
procedure TFrmMain.N327Click(Sender: TObject); var FWord :Variant; FDoc :Variant; strSQL :string; begin //首先创造对象,如果出现异常就做出提示 try FWord := CreateOleObject("Word.Application"); //WOrd程序的执行是否可见,值为false时,程序在后台运行。
FWord.Visible := True; except messagebox(0,"创建word对象失败!","警告",MB_OK+MB_ICONINFORMATION); exit; end; strSQL :="select * From "B_T_Company_Infor""; with dm.ClientDataSet_Temp do begin if Active then Active:=False; CommandText:=strSQL; Open; end; //现在打开的Word中,创建一个新的页面,然后在其中键入需要的内容 try FDOC :=FWord.Documents.Add; {对于Word的新页面} FWord.Selection.Font.Name :="宋体"; FWord.Selection.Font.Size :=20; FWord.Selection.Font.Bold :=2; FWord.Selection.paragraphs.Alignment := wdAlignParagraphCenter; FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[0].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph; FWord.Selection.paragraphs.Alignment := wdAlignParagraphLeft; FWord.Selection.Font.Size :=12; FWord.Selection.Font.Bold :=0; FWord.Selection.TypeText(" 现将我社组团部的"); FWord.Selection.TypeText(" "); FWord.Selection.TypeText("团计划发出,各地请按下列行程做接待,并及早落实"+ "团队计划和选派优秀导游员。
各地代订住宿、火车票、机票务必安排好接待,日程"+ "如有变更,及时与下站接待社或本社联系,各地接团时请举【"+ dm.ClientDataSet_Temp.Fields[0].AsString+"】接站牌。
"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("请速回传真确认,谢谢合作!"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("人数:"); FWord.Selection.TypeText("人数:"); FWord.Selection.TypeText("国籍:"); FWord.Selection.TypeText("国籍:"); FWord.Selection.TypeText("等级:"); FWord.Selection.TypeText("等级:"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("这里是团队安排"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("TO: "); FWord.Selection.TypeText("12345678901234567890"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("TEL: "); FWord.Selection.TypeText("12345678901234567890"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("FAX: "); FWord.Selection.TypeText("12345678901234567890"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("______________________________________________"); FWord.Selection.Typeparagraph;//换行 FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("FROM: "); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[0].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("TEL: "); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[3].AsString); FWord.Selection.Typeparagraph;//换行 FWord.Selection.TypeText("FAX: "); FWord.Selection.TypeText(dm.ClientDataSet_Temp.Fields[4].AsString); FWord.Selection.Typeparagraph;//换行 Except on e: Exception do Messagebox(0,Pchar(e.Message),"警告",MB_OK+MB_ICONINFORMATION); end; //保存文档 FWord.Caption := "组团计划保存在: "+ExtractFilePath(application.ExeName)+"Reports\GroupPlan.doc"; FDOC.SaveAS(ExtractFilePath(application.ExeName)+"Reports\GroupPlan.doc"); if messagebox(0,"组团计划已经保存成功!"+chr(13)+chr(13)+ "单击【确定】退出Word,返回到程序中!","您确信要退出Word吗?", MB_YESNO+MB_ICONINFORMATION+MB_DEFBUTTON2)=IDYES then begin FWord.Quit; FWord := Unassigned; end; end; ----------------------------- Delphi与Word之间的融合技术(1) 一、VBA代码含义 Microsoft Word是一个集成化环境,是美国微软公司的字处理系统,但是它决不仅仅是一个字处理系统,它集成了Microsoft Visual Basic,可以通过编程来实现对Word功能的扩展。
Microsoft Visual Basic在word中的代码即Word的宏,通过编写Word宏,可实现一些文档处理的自动化,如实现文档的自动备份、存盘等,可扩展Word文档的功能,因此,能够充分利用Word的特性,甚至使Word成为自己软件的一部分。
Word的宏既有有利的一部分,因为它能够帮助我们实现文档的自动化,但是Word的宏也不是纯粹的有利,有时它可能危害我们的文档、计算机系统甚 至网络,从最开始的Taiwan NO1宏病毒到现在的...
按键精灵读取逐行读取TXT文档,一次读取一行
Text = Plugin.File.ReadFileEx("d:\我的文档\桌面\新建 文本文档.txt")//文档位置你自己改dim MyArrayMyArray = Split(Text, "|")If UBound(MyArray)>=0 Then i=0 For UBound(MyArray) //下面这句是得到文本内容 SayString Cstr(MyArray(i)) Delay 1000Msgbox "成功输入第 " & i+1 &" 行文本内容为:"& Cstr(MyArray(i)) Delay 1000 i=i+1 NextEnd If...
vb 逐行读取文本文件
完美源码:@echo offsetlocal enabledelayedexpansionset /p =c.txtfor /f "delims=" %%a in (a.txt) do (for /f "delims=" %%b in ("type b.txt ^| find "%%a"") do (set same=noset word=%%bfor /f "delims=" %%c in (c.txt) do (if "!word!"=="%%c" set same=yes)if "!same!"=="no" echo !word!>>c.txt))set /p =已完成!endlocal
关于C语言中文本文件的逐行读取的实现
/读取一行到buf}void someprocess(char *buf){ printf("/这里的操作你自己定义}void main() { FILE *fp; char *buf, filename[20], *p; printf("input file name:"); gets(filename); if ((fp=fopen(filename;))==NULL) { printf("/每次调用文件指针fp会自动后移一行 if(;, buf);/open file error!!\n"); return#include #define LINE 1024char *ReadData(FILE *fp; } buf=(char*)malloc(LINE*sizeof(char));stdio; while(1) { p=ReadData(fp, buf);/文件读取结束则跳出循环 break.h> #include <stdlib, "r", fp);/...
请问在Delphi程序中,如何将所有变量生成到一个Word文档,?
procedure TForm1.Button1Click(Sender: TObject);vartmplist: tstringlist;i, j: integer;tel: string;begintel := "1300000000"; //指定电话号码 如果用edit1控件则改成 edit1.texttmplist := tstringlist.Create; //创建tmplist.LoadFromFile("文件路径"); //载入文本,路径自行确定for i:= 0 to tmplist.Count - 1 do //循环beginif pos(tel, tmplist.Strings[i]) >0 then //当查到电话号码所在行时beginj := 1;while j beginmemo1.lines.add(tmplist.Strings[i + j]); //将后10行记录写入memoinc(j); //j递增1end;break;end;end;tmplist.Free;end;//由于文本文件的内容示例没有,不知道排列,只能大致写一个,楼主可以根据文本的排列规则进行修改,不明处可以追问
-
给我们打电话
7*24小时服务热线:1399999999
全国客服热线:400-0000-000 -
百度地图
福建省漳州市 -
给我们发邮件
E-mail:[email protected]
在线沟通