哇! ReportMachine的whf也来了啊!失敬!失敬!
To mmtxm:
我用的是FastReport;
在服务端生成报表文件, 既 *.frp文件,即
frReport1.PrepareReport;
frReport1.SavePreparedReport(xxxxx);
然后读取、编码文件:
uses
EncdDecd, Zlib;
function CompressAndEncode(const input: string): string;
//编码函数
var
fCompressedStream: TMemoryStream;
fStreamCompressor: TCompressionStream;
fStringStream: TStringStream;
begin
fCompressedStream := TMemoryStream.Create;
try
fStreamCompressor := TCompressionStream.Create(clDefault,
fCompressedStream);
try
fStreamCompressor.Write(input[1], length(input));
finally
FreeAndNil(fStreamCompressor);
end;
fStringStream := TStringStream.create('');
try
fCompressedStream.Position := 0;
EncodeStream(fCompressedStream, fStringStream);
Result := fStringStream.datastring;
finally
FreeAndNil(fStringStream);
end;
finally
FreeAndNil(fCompressedStream);
end;
end;
function BianMa(nfilename:string):string;//读取和编码
var
MyFileStream :TFileStream;
Buffer :String;
begin
try
MyFileStream:=TFileStream.Create(nfilename,fmOpenRead);
SetLength(buffer, MyFileStream.Size);
MyFileStream.Read(Buffer[1], MyFileStream.Size);
Buffer:=CompressAndEncode(Buffer);
//得到编码后的字符串
finally
MyFileStream.Free;
//eventually
end;
if buffer<>'' then
result:=buffer
else
result:='No Data';
end;
以上是在COM OLE对象要用的返回函数,返回字符串!
用在<textarea id='RMVIEWER_DATA' style='display:none'> com ole返回这里的字符串 </textarea>;
目的主要是要生成象如意报表的网页框架!
跟着是ActiveForm要调用的函数和方法!目的是把嵌在textarea id='RMVIEWER_DATA' style='display:none'> com ole返回这里的字符串 </textarea>的编码字符串变回文件;
function DecodeAndUnCompress(const input: string): string;
//解码
var
fWorkStream: TMemoryStream;
fEncodedStream: TMemoryStream;
fStreamDeCompressor: TDeCompressionStream;
fBufLen: integer;
fBuffer: array[0..16383] of byte;
begin
fWorkStream := TMemoryStream.create;
try
fWorkStream.size := length(input);
move(input[1], fWorkStream.memory^, fWorkStream.size);
fWorkStream.position := 0;
fEncodedStream := TMemoryStream.create;
try
DecodeStream(fWorkStream, fEncodedStream);
fWorkStream.size := 0;
fEncodedStream.position := 0;
fStreamDeCompressor :=
TDeCompressionStream.create(fEncodedStream);
try
fBufLen := fStreamDeCompressor.Read(fBuffer, SizeOf(fBuffer));
while fBufLen > 0do
begin
fWorkStream.Write(fBuffer, fBufLen);
fBufLen := fStreamDeCompressor.Read(fBuffer,
SizeOf(fBuffer));
end;
finally
FreeAndNil(fStreamDeCompressor);
end;
finally
FreeAndnil(fEncodedStream);
end;
fWorkStream.position := 0;
SetLength(Result, fWorkStream.size);
move(fWorkStream.memory^, Result[1], fWorkStream.size);
finally
FreeAndNil(fWorkStream);
end;
procedure jiema(ss,nfilename:string);
var
Stream:TMemoryStream;
Res:string;
begin
Stream:=TMemoryStream.Create;
try
//DecodeAndUnCompress
// Res:=DecodeString(ss);
Res:=DecodeAndUnCompress(ss);//解码函数!
Stream.Write(Res[1],Length(Res));
Stream.SaveToFile(nfilename);
finally
Stream.Free;
end;
end;
跟着在ActiveForm 生成报表文件调用:
frReport1.LoadPreparedReport(file);
frReport1.ShowPreparedReport;
至于要自定以的话!可将设计文件即*.frf和数据文件一起嵌在网页送过来!只不过
解码就要复杂一点了!设计完成文件可用ftp或POST到服务端!这个本人还未实践啊!
因我这里暂用不到这功能!哈哈!
过程有点乱!因本人墨水有限啊!谢谢观赏及指教!