Table表的数据转换为HTML页时分页的问题(100分)

  • 主题发起人 主题发起人 wqhatnet
  • 开始时间 开始时间
W

wqhatnet

Unregistered / Unconfirmed
GUEST, unregistred user!
var
i,j,w,h:integer;
list:TStringlist;
begin
list:=TStringlist.Create;
list.add('<html>');
list.add('<head>');
list.add('<title>库存报表</title>');
list.add('<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">');
list.add('</head>');
list.add('');
list.add('<body bgcolor="#FFFFFF" text="#000000">');
list.add('<table width="100%" border="1" cellspacing="0" bordercolor="#000000">');
list.add(' <tr> ');
list.add(' <td colspan="9"> ');
list.add(' <div align="center"><font face="宋体"><b><font size="+2">库存报表</font></b></font></div>');
list.add(' </td>');
list.add(' </tr>');
/////////////////////////////
list.add(' <tr> ');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[0].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[1].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[2].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[3].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[4].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[5].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[6].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[7].DisplayName+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[8].DisplayName+'</div>');
list.add(' </td>');
list.add(' </tr>');
/////////////////////////////
try
AForm.Table1.DisableConstraints;
AForm.Table1.First;
for j:=0 to AForm.table1.recordcount-1do
begin
list.add(' <tr> ');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[0].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[1].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[2].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[3].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[4].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[5].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[6].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[7].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[8].asString+'</div>');
list.add(' </td>');
list.add(' </tr>');
AForm.Table1.Next;
end;
Finally
end;
/////////////////////////////////
list.add('</table>');
list.add('</body>');
list.add('</html>');
list.SaveToFile(ExtractFilePath(Application.exename)+'config/ShoesDb.htm');
ShellExecute(handle, pchar('open'), pchar(ExtractFilePath(Application.exename)+'config/ShoesDb.htm'), pchar(''), pchar(''), SW_SHOWNORMAL);
list.Destroy;
end;
 
不知道你是什么意思?是想分页吗?
如果是用的ADO,那么本身就有一个_Recordset中的PageSize和PageCount等等的属性,做分页是再好不过啦!
 
幸好我自己搞的定
要不然就连胡子都要等的长出来了
[8D]
 
var
i,j,w,h,count,endcount,page,backPage,NextPage,endPage:integer;
list,bgnlist,endlist:TStringlist;
begin
count:=0;
page:=1;
backPage:=1;
w:=editw.value;
endcount:=editcount.Value;
endPage:=(AForm.table1.recordcount) div (endcount);
if (AForm.table1.recordcount) mod (endcount)<>0 then
endPage:=endpage+1;
msg.panels[0].text:=' 共'+intToStr(endPage)+'页';
list:=TStringlist.Create;
bgnlist:=TStringlist.Create;
endlist:=TStringlist.Create;
bgnlist.add('<html>');
bgnlist.add('<head>');
bgnlist.add('<title>库存报表</title>');
bgnlist.add('<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">');
bgnlist.add('</head>');
bgnlist.add('');
bgnlist.add('<body bgcolor="#FFFFFF" text="#000000">');
bgnlist.add('<table width="'+intToStr(w)+'%" border="1" cellspacing="0" bordercolor="#000000" align="center">');
bgnlist.add(' <tr> ');
bgnlist.add(' <td colspan="9"> ');
bgnlist.add(' <div align="center"><font face="宋体"><b><font size="+2">库存报表</font></b></font></div>');
bgnlist.add(' </td>');
bgnlist.add(' </tr>');
/////////////////////////////
bgnlist.add(' <tr> ');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[0].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[1].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[2].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[3].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[4].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[5].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[6].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[7].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' <td> ');
bgnlist.add(' <div align="center">'+AForm.table1.Fields[8].DisplayName+'</div>');
bgnlist.add(' </td>');
bgnlist.add(' </tr>');
///////////////////////////
list.Text:=bgnlist.Text;
try
AForm.Table1.DisableConstraints;
AForm.Table1.First;
for j:=0 to AForm.table1.recordcount-1do
begin
Application.ProcessMessages;
if count>endcount-1 then
begin
count:=0;
backPage:=Page-1;
nextPage:=Page+1;
if Nextpage>endPage then
NextPage:=endPage;
if Backpage<1 then
BackPage:=1;
/////////////////////////////
endlist.add('</table>');
//
endlist.add('<table width="'+intToStr(w)+'%" border="1" cellspacing="0" align="center">');
endlist.add(' <tr>');
endlist.add(' <td>');
endlist.add(' <table width="20%" border="0" cellspacing="0" align="left">');
endlist.add(' <tr>');
endlist.add(' <td> ');
endlist.add(' <div align="center"><a href="ShoesDb1.htm" target="_self">首页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(backPage)+'.htm" target="_self">上页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(nextPage)+'.htm" target="_self">次页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(endPage)+'.htm" target="_self">尾页</a></div>');
endlist.add(' </td>');
endlist.add(' </tr>');
endlist.add(' </table>');
endlist.add(' </td>');
endlist.add(' </tr>');
endlist.add('</table>');
//
endlist.add('</body>');
endlist.add('</html>');
////////////////////////////
list.Add(endlist.text);
endlist.text:='';
list.SaveToFile(ExtractFilePath(Application.exename)+'config/ShoesDb'+intToStr(page)+'.htm');
list.Clear;
list.Text:=bgnlist.Text;
page:=Page+1;

end;
//end if
count:=count+1;
list.add(' <tr> ');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[0].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[1].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[2].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[3].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[4].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[5].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[6].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[7].asString+'</div>');
list.add(' </td>');
list.add(' <td> ');
list.add(' <div align="center">'+AForm.table1.Fields[8].asString+'</div>');
list.add(' </td>');
list.add(' </tr>');
AForm.Table1.Next;
end;
except
abort;
end;
/////////
backpage:=backPage+1;
if endPage=2 then
backPage:=1;
endlist.add('</table>');
//
endlist.add('<table width="'+intToStr(w)+'%" border="1" cellspacing="0" align="center">');
endlist.add(' <tr>');
endlist.add(' <td>');
endlist.add(' <table width="20%" border="0" cellspacing="0" align="left">');
endlist.add(' <tr>');
endlist.add(' <td> ');
endlist.add(' <div align="center"><a href="ShoesDb1.htm" target="_self">首页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(backPage)+'.htm" target="_self">上页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(nextPage)+'.htm" target="_self">次页</a></div>');
endlist.add(' </td>');
endlist.add(' <td>');
endlist.add(' <div align="center"><a href="ShoesDb'+intToSTr(endPage)+'.htm" target="_self">尾页</a></div>');
endlist.add(' </td>');
endlist.add(' </tr>');
endlist.add(' </table>');
endlist.add(' </td>');
endlist.add(' </tr>');
endlist.add('</table>');
//
endlist.add('</body>');
endlist.add('</html>');
////////////////////////////
list.Add(endlist.text);
/////////////////////////////////
list.SaveToFile(ExtractFilePath(Application.exename)+'config/ShoesDb'+intToStr(page)+'.htm');
/////////////////////////////
TBOpenHtml.hint:=ExtractFilePath(Application.exename)+'config/ShoesDb1.htm';
printshoesdbform.WebBrowser1.Navigate(TBOpenHtml.hint);
list.Destroy;
bgnlist.Destroy;
endlist.Destroy;
end;
 
接受答案了.
 
后退
顶部