300分求(急):delphi中实现将多个jpg文件按文件的时间顺序读入word([b]郑重承诺:如果8月4日解决,再送200分!!![/b]) ( 积分: 3

  • 主题发起人 主题发起人 liangcqsuper
  • 开始时间 开始时间
L

liangcqsuper

Unregistered / Unconfirmed
GUEST, unregistred user!
300分求(急):delphi中实现将多个jpg文件按文件的时间顺序读入word(郑重承诺:如果8月4日解决,再送200分!!!) ( 积分: 300 )<br />如题,
程序描述:
1.到指定文件夹中查找所有.jpg文件,按时间顺序读取;
2.一个一个文件往word里面插入;
3.保存word文件,同时插入db2数据库.

郑重承诺:如果8月4日解决,再送200分!!!
 
如题,
程序描述:
1.到指定文件夹中查找所有.jpg文件,按时间顺序读取;
2.一个一个文件往word里面插入;
3.保存word文件,同时插入db2数据库.

郑重承诺:如果8月4日解决,再送200分!!!
 
找到JPG文件插入WORD容易,保存WORD文件插入DB2是什么意思?是把WORD文件存到DB2里边吗?
 
对的.我求的是代码,谢谢!
 
做程序员应该勤劳一点的呀,您分明就是不想自己动手动脑嘛。说出个1,2,3,让别人替你做?
 
呵呵,查一查BLOB字段地用法吧!!!
 
不是不动脑经,水平有限,又很急,所以求助!
如果不愿意提供源码,可以不回帖的嘛!谢谢合作!
 
我给你一段WORD拷入数据库的,不过对于DB2来说,它的驱动引擎是如何的,支不支持ADO,我就不清楚了
word文件传入和传出数据库。

uses IdGlobal;
procedure TdjhyForm.SpeedButton2Click(Sender: TObject);
var
sfilename:string;

function BlobContentTostring(const Filename:string):string;
begin
with Tfilestream.Create(filename,fmopenread) do
try
setlength(result,size);
read(pointer(result)^,size);
finally
free;
end;
end;
begin
if opendialog1.Execute then
begin
sfilename:=opendialog1.FileName;
DataModule1.ADOQuery14.Edit;
DataModule1.ADOQuery14.FieldByName('word').AsString:=blobcontenttostring(sfilename);
DataModule1.ADOQuery14.Post;
end;
end;

procedure TdjhyForm.SpeedButton1Click(Sender: TObject);
var
sfilename:string;
bs:Tadoblobstream;
begin
bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word')),bmread);
try
sfilename:=extractfilepath(application.ExeName)+trim(DataModule1.adoquery14.fieldbyname('hybh').AsString);
sfilename:=sfilename+'.'+'doc';
bs.SaveToFile(sfilename);
try
djhyopenform:=Tdjhyopenform.Create(self);
djhyopenform.olecontainer1.CreateObjectFromFile(sfilename,false);
djhyopenform.OleContainer1.Iconic:=true;
djhyopenform.ShowModal;
finally
djhyopenform.Free;
end;
finally
bs.free;
end;
end;
 
这还有一个资料,看看吧
用delphi批量导入某子目录下所有JPG图片文件到数据库 选择自 mzyp2002 的 Blog
关键字 用delphi批量导入某子目录下所有JPG图片文件到数据库
出处

//保存图片到数据库
function imagesavetosql(dataset:TQuery;filename:String):boolean;
var
imagejpg:TJPEGImage; //jpg图片
MyStm:TMemoryStream;
begin
result:=false;
MyStm:=TMemoryStream.Create;
imagejpg:=Tjpegimage.Create;
if filename<>'' then
begin
imagejpg.LoadFromFile(filename);
imagejpg.SaveToStream(MyStm);
MyStm.Position:=0;
TBlobField(dataset.FieldByName('pict')).LoadFromStream(MyStm); //不可与DMImage之类控件,因为其只支持BMP
result:=true;
end;
MyStm.Free;
imagejpg.free;
end;
//界面上添加TDirectoryListBox,TGauge控件
procedure Tfrmpict.BitBtn2Click(Sender: TObject);
var
dirlist:TStringList;
i:Integer;
begin
inherited;
if chk_road.Checked then
begin
dirlist:=TStringList.Create ;
dirlist.Clear;
try
GetAllFileName(DirectoryListBox1.Directory,dirlist);
if dirlist.Count>0 then
begin
Gauge1.MinValue :=0;
Gauge1.MaxValue:= dirlist.Count-1;
for i:=0 to dirlist.Count-1 do
begin
with dm.qry_pict do
begin
Insert;
Fields[0].AsString:=copy(dirlist.Strings,1,pos('.',dirlist.Strings)-1);
if imagesavetosql(dm.qry_pict,dirlist.Strings )=false then
begin
ShowMessage('导入'+dirlist.Strings+'.jpg图片时出错');
Abort;
end;
Post;
end; //with
Gauge1.AddProgress(1);
end; //for
end //if
else
ShowMessage('该目录下不存在JPG类型图片');

finally
dirlist.Free;
end;

end
else
ShowMessage('请执行路径选取操作');

//Close;
end;




作者Blog:http://blog.csdn.net/mzyp2002/
 
我要所有jpg文件导入word
 
//以下代码将某目录下jpg文件找出并按时间顺序存入 slfile
unit UntMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DateUtils, Types;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
function SearchFiles(sDir: String):boolean; //在指定目录下查找文件
procedure AccordDateSort(sDir: String); //根据时间排序文件
// 取文件时间
function GetFileDate(const FileName: string; var CreationTime, LastWriteTime, LastAccessTime:
TFileTime): Boolean;

function GetFileModifyTime(const strFileName: string): TDateTime; //获得文件的修改时间
function CovFileDate(Fd: _FileTime): TDateTime; // 转换文件的时间格式

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
slFile : TStringList; //所有的指定后缀名的文件

const
_DirName : string = 'C:/Documents and Settings/fenian/桌面/SaveJpg';
_Ext : string = '.jpg'; //需要处理的文件的后缀名

implementation

uses UntPub;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
sDir: string;
begin
sDir := ExcludeTrailingPathDelimiter(_DirName);
sDir := sDir + '/';

if not DirectoryExists(_DirName) then //目录不存在
begin
MsgDlgInfo(Application.Handle,_DirName+' 不存在!');
Exit;
end;

if not SearchFiles(_DirName) then
begin
MsgDlgInfo(Application.Handle,'不存在指定的文件!');
Exit;
end;

AccordDateSort(_DirName);

for i:=0 to slFile.Count-1 do
showmessage(sDir+slFile.Strings);
end;

function TForm1.SearchFiles(sDir: String): boolean;
var
SearchRec : TSearchRec;
sCurDir:String;
begin
sDir := ExcludeTrailingPathDelimiter(sDir);
sDir := sDir + '/';
sCurDir:=GetCurrentDir;
try
SetCurrentDir(sDir); //设置当前目录
slFile.Clear;
if FindFirst(sDir+'*'+_Ext, faAnyFile, SearchRec)<>0 then
begin
Result := false;
exit;
end;

if (SearchRec.Attr and faDirectory)=0 then
slFile.Add(SearchRec.Name);

while FindNext(SearchRec) = 0 do
begin
if (SearchRec.Attr and faDirectory)=0 then
slFile.Add(SearchRec.Name);
end;
Result := true;
FindClose(SearchRec);
finally
ChDir(sCurDir);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
slFile := TStringList.Create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
slFile.Free;
end;

procedure TForm1.AccordDateSort(sDir: String); //从早到晚排列
var
i,j: integer;
sTmp: String;
lpCreationTime,lpLastAccessTime,lpLastWriteTime: TFILETIME;
begin
sDir := ExcludeTrailingPathDelimiter(sDir);
sDir := sDir + '/';

for i:=0 to slFile.Count-2 do //冒泡
begin
for j:=0 to slFile.Count-2-i do
if CompareDateTime(GetFileModifyTime(sDir+slFile.Strings[j]),
GetFileModifyTime(sDir+slFile.Strings[j+1])) = GreaterThanValue then
begin
sTmp := slFile.Strings[j];
slFile.Strings[j] := slFile.Strings[j+1];
slFile.Strings[j+1] := sTmp;
end;
end;
end;

function TForm1.GetFileDate(const FileName: string; var CreationTime,
LastWriteTime, LastAccessTime: TFileTime): Boolean;
var
FileHandle: Integer;
begin
FileHandle := FileOpen(FileName, fmOpenRead or fmShareDenyNone);
if FileHandle > 0 then
begin
GetFileTime(FileHandle, @CreationTime, @LastAccessTime, @LastWriteTime);
FileClose(FileHandle);
Result := True;
end
else
Result := False;
end;

function TForm1.GetFileModifyTime(const strFileName: string): TDateTime;
var
Tp: TSearchRec; //申明Tp为一个查找记录
begin
FindFirst(strFileName, faAnyFile, Tp); { 查找目标文件 }
FindClose(Tp);
result := CovFileDate(Tp.FindData.ftLastWriteTime); //修改时间
end;

function TForm1.CovFileDate(Fd: _FileTime): TDateTime;
var
Tct: _SystemTime;
Temp: _FileTime;
begin
FileTimeToLocalFileTime(Fd, Temp);
FileTimeToSystemTime(Temp, Tct);
CovFileDate := SystemTimeToDateTime(Tct);
end;

=========================
unit UntPub;

interface
uses
Windows, Forms, Controls;

procedure MsgDlgInfo(const Handle: THandle; const Text: string);


implementation

{弹出提示信息框}
procedure MsgDlgInfo(const Handle: THandle; const Text: string);
begin
MessageBox(Handle, PChar(Text), PChar(Application.Title), MB_OK + MB_ICONINFORMATION + MB_TOPMOST);
end;

end.
 
真是高手!我看得打脑口!!
 
总得自己动手整合一下吧?盖茨也没帮俺们把电脑整得可以开口它就听话帮你做事的份上啊???
 
呵呵,正在整理,同时再看有没有更好的解决方案.................
 
感谢各位的帮助,对给出源码的app2001和fenian分配分值!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部