📄 htmutils.pas
字号:
unit htmutils;
interface
uses classes,sysutils,db,adodb,Grids,windows;
function datasettohtm(dset:Tdataset;htmlines:tstrings;autoid:boolean;processhandle:cardinal):boolean;
function strgridtohtm(strgrid:Tstringgrid;htmlines:tstrings):boolean;
function exhtmlkey(s:String):string;
const
htmspace=' ';
htmhead='<html><head><meta HTTP-EQUIV="Content-Type" Content="text-html; charset=gb2312"><title></title></head><body>';
htmltabhead='<table border=1 cellSpacing=0 cellPadding=0 borderColorLight=white>';
htmtabtail='</table>';
htmtail='</body></html>';
WM_PROCESS=11298;
var converthtmsring:boolean;
implementation
function exhtmlkey(s:String):string;
begin
result:=s;
//result:=stringreplace(s,' ',' ',[rfreplaceall]);
result:=stringreplace(result,#$D#$A,'<br>',[rfreplaceall]);
result:=stringreplace(result,'<','<',[rfreplaceall]);
result:=stringreplace(result,'>','>',[rfreplaceall]);
result:=stringreplace(result,#$9,' ',[rfreplaceall]);
end;
function datasettohtm(dset:Tdataset;htmlines:tstrings;autoid:boolean;processhandle:cardinal):boolean;
var i,j,l:cardinal;
tstr:string;
begin
result:=false;
try
htmlines.Clear;
if not dset.eof then
dset.First;
htmlines.Add(htmhead);
htmlines.Add(htmltabhead);
l:=dset.FieldCount;
tstr:='<tr bgcolor=#e7eaea>';
if autoid then
tstr:=tstr+'<td>id</td>'#$D#$A;
for i:=0 to l-1 do
begin
tstr:=tstr+'<td>'+exhtmlkey(dset.Fields[i].FieldName)+'</td>'+#$D#$A;
end;
tstr:=tstr+'</tr>';
htmlines.Add(tstr);
l:=dset.RecordCount;
if l>0 then
for i:=0 to l-1 do
begin
tstr:='<tr>';
if autoid then
tstr:=tstr+'<td>'+inttostr(i+1)+'</td>'+#$D#$A;
for j:=0 to dset.FieldCount-1 do
begin
if dset.Fields[j].IsNull then
begin
if dset.Fields[j].DataType=ftString then
tstr:=tstr+'<td>'+htmspace+'</td>'+#$D#$A
else
begin
if (dset.Fields[j].DataType=ftSmallint) or
(dset.Fields[j].DataType=ftInteger) or
(dset.Fields[j].DataType=ftWord) or
(dset.Fields[j].DataType=ftFloat) or
(dset.Fields[j].DataType=ftCurrency) or
(dset.Fields[j].DataType=ftAutoInc) or
(dset.Fields[j].DataType=ftLargeint) then
tstr:=tstr+'<td>0</td>'+#$D#$A
else
tstr:=tstr+'<td></td>'+#$D#$A;
end;
end
else
tstr:=tstr+'<td>'+exhtmlkey(dset.Fields[j].AsString)+'</td>'+#$D#$A
end;
tstr:=tstr+'</tr>' ;
htmlines.Add(tstr);
if not dset.eof then
begin
dset.Next;
end;
windows.SendMessage(processhandle,WM_PROCESS,0,i*100 div l);
end;
htmlines.Add(htmtabtail);
htmlines.Add(htmtail);
result:=true;
finally
windows.SendMessage(processhandle,WM_PROCESS,0,i*100 div -1);
end;
end;
function strgridtohtm(strgrid:Tstringgrid;htmlines:tstrings):boolean;
var i,j:cardinal;
tstr,tstr2:string;
begin
result:=false;
try
htmlines.Clear;
htmlines.Add(htmhead);
htmlines.Add(htmltabhead);
for i:=0 to strgrid.RowCount-1 do
begin
tstr:='<tr>';
for j:=0 to strgrid.ColCount-1 do
begin
tstr2:=strgrid.Cells[j,i];
if tstr2='' then
tstr:=tstr+'<td>'+htmspace+'</td>'+#$D#$A
else
tstr:=tstr+'<td>'+exhtmlkey(tstr2)+'</td>'+#$D#$A
end;
tstr:=tstr+'</tr>';
htmlines.Add(tstr);
end;
htmlines.Add(htmtabtail);
htmlines.Add(htmtail);
result:=true;
finally
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -