导航:首页 > 编程语言 > jsp页面打印表格

jsp页面打印表格

发布时间:2025-03-31 17:09:09

jsP页面打印表格“预览有边框,打印无边框”咋整

<table class="Table1" cellpadding="0" cellspacing="0">
<tr><td>这</td><td>就</td><td>行</td></tr>
<tr><td>你</td><td>试</td><td>试</td></tr>
</table>
样式:
.Table1 {
border-top: 1px solid #000;
border-left: 1px solid #000;
}
.Table1 tr td {
border-right: 1px solid #000;
border-bottom: 1px solid #000;
}

❷ 用JSP生成一个表格

java">提交页面:page01.jsp
<%@pagecontentType="text/html"pageEncoding="gbk"%>
<html>
<head></head>
<body>
<formaction="page02.jsp"method="post">
请输入表格的行数:<inputtype="text"name="rolNum"/><br/>
请输入表格的列数:<inputtype="text"name="colNum"/><br/>
<inputtype="submit"value="提交"/>
<inputtype="reset"value="重置"/>
</form>
</body>
</html>
生成表格的页面:page01.jsp
<%@pagecontentType="text/html"pageEncoding="gbk"%>
<html>
<head></head>
<body>
<%
//接口参数
StringcolStr=request.getParameter("colNum");
StringrolStr=request.getParameter("rolNum");
intcolNum=0;
introlNum=0;
//类型转化
try{
rolNum=Integet.parseInt(rolStr);
colNum=Integet.parseInt(colStr);
}catch(Exceptione){
}
%>
<!--循环输出表格-->
<tableborder="1">
<%
for(inti=0;i<rolNum;i++){
%>
<tr>
<%
for(intj=0;j<colNum;j++){
%>
<td><%=i*j%></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>

❸ 能否在jsp页面显示excel表格呢

操作excel需要导入操作excel的jar。比如poi什么的。
1用它把excel的值取出来。
2定义一个类,有4个field 分别为 id,name,sex,age.和get、set方法。装数据用的
3把取到的值放入对象,并添加到List中。
4在页面遍历List中的对象的值。

❹ jsp自动生成表格问题

采用c标签
首先需要导入一个jar包:
jstl.jar(WebRoot\WEB-INF\lib目录下)
然后在需要引入的标签中加入下面语句:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

然后在你需要使用的地方写上

<table>
<tr>
<td>ID</td>

<td>Name</td>
<td>Password</td>
</tr>

<c:forEach var=”user" items=”userList" varStatus=”status”>
<tr>
<td>${user.id}</td>

<td>${user.Name}</td>
<td>${user.Password}</td>
</tr>
</c:forEach>

</table>

C:foreach标签相关属性,请参见:
http://luoke920.iteye.com/blog/258815

❺ 在JSP中如何实现表格正的整页打印

直接调用windows的打印是没戏了
你可以使用程序来先输出一个样式,然后按这个样式去打印

我们之前做了一个用itext组件,在线生成PDF,可以精确两个边与内容的间距
你可以试试看

这是同事写的,你参考下吧,
/**
* 个人总结打印 正
* @param path
* @return
*/
public boolean createPDF1(SumVo sum,HttpServletResponse response){

Document document = new Document(PageSize.A4,33,31,72,30);//建立一个Document对象
ByteArrayOutputStream ba = new ByteArrayOutputStream();
try{
PdfWriter writer = PdfWriter.getInstance(document, ba);
//PdfWriter.getInstance(document,new FileOutputStream(path));//建立一个PdfWriter对象
document.open();
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//设置中文字体
Font headFont = new Font(bfChinese, 10, Font.BOLD);//设置字体大小
Font headFont1 = new Font(bfChinese, 10, Font.NORMAL);//设置字体大小
Font headFont2 = new Font(bfChinese, 14, Font.NORMAL);//设置字体大小
float[] widths = {72f ,72f ,72f ,80f ,72f ,72f };//设置表格的列宽
PdfPTable table = new PdfPTable(widths);//建立一个pdf表格

table.setTotalWidth(440);//设置表格的宽度
table.setLockedWidth(true);

PdfPCell cell = new PdfPCell(new Paragraph(sum.getExam().getName(),headFont2));//建立一个单元格
cell.setBorder(0);
cell.setFixedHeight(40);
cell.setColspan(6);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);//设置内容水平居中显示
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("考核对象",headFont));//建立一个单元格
cell.setBorderWidth(1.5f);
cell.setFixedHeight(20);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getUser().getCname(),headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("岗位",headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getUser().getDuty().getName(),headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("填表日期",headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getCtime().substring(0,10),headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("个人总结 \t(限1500字)",headFont1));
cell.setBorderWidth(1.5f);
cell.setFixedHeight(657);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);//设置内容水平居中显示
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getScontent(),headFont1));
cell.setBorderWidth(1.5f);
cell.setFixedHeight(657);
cell.setColspan(5);
table.addCell(cell);
document.add(table);
document.close();
response.setContentType("application/pdf");
response.setContentLength(ba.size());
ServletOutputStream out = response.getOutputStream();
ba.writeTo(out);
out.flush();
} catch (DocumentException de) {
System.err.println(de.getMessage());
return false;
}
catch (IOException ioe) {
System.err.println(ioe.getMessage());
return false;
}
return true;
}
/**
* 打印 个人总结 反面
* @param path
* @param sum
* @return
*/
public boolean createPDF2(SumVo sum,HttpServletResponse response){

Document document = new Document(PageSize.A4,32,31,72,30);
ByteArrayOutputStream ba = new ByteArrayOutputStream();
try{
PdfWriter writer = PdfWriter.getInstance(document, ba);
//PdfWriter.getInstance(document,new FileOutputStream("c:/ss.pdf"));//建立一个PdfWriter对象
document.open();
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//设置中文字体
BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font headFont = new Font(bfChinese, 10, Font.BOLD);
Font headFont1 = new Font(bfChinese, 10, Font.UNDERLINE);
Font font = new Font(bfComic, 12);
Font font1 = new Font(bfComic, 12,Font.UNDERLINE);
float[] widths = {70f, 340f };
PdfPTable table = new PdfPTable(widths);
table.setTotalWidth(440);
table.setLockedWidth(true);

PdfPCell cell = new PdfPCell(new Paragraph("考勤情况",headFont));
cell.setBorderWidth(1.5f);
cell.setFixedHeight(100);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getAttendance(),headFont));
cell.setBorderWidth(1.5f);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("综合评分",headFont));
cell.setBorderWidth(1.5f);
cell.setFixedHeight(100);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getComp(),headFont));
cell.setBorderWidth(1.5f);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("\n\n\n部门考核意见",headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(13);
cell.setFixedHeight(192);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getDepview(),headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(13);
table.addCell(cell);

cell = new PdfPCell();
cell.setBorderWidth(1.5f);
cell.setBorder(14);
cell.setFixedHeight(45);
table.addCell(cell);
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf1 =new SimpleDateFormat("yyyy年\tMM\t月\tdd\t日");
String date ="年 \t月 \t日 ";
try {
if(sum.getDeptime()!=null&&sum.getDeptime()!=""){
date =sdf1.format(sdf.parse(sum.getDeptime()));
}
} catch (ParseException e) {
e.printStackTrace();
}
cell = new PdfPCell(new Paragraph(date+" ",headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(14);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);

cell = new PdfPCell(new Paragraph(" \n\n个人意见",headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(13);
cell.setFixedHeight(75);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getMyview(),headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(13);
table.addCell(cell);
cell = new PdfPCell();
cell.setBorderWidth(1.5f);
cell.setBorder(14);
cell.setFixedHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("签名: \n 年 \t月 \t日 ",headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(14);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("\n\n\n\n院考核意见",headFont));
cell.setBorderWidth(1.5f);
cell.setBorder(13);
cell.setFixedHeight(60);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
String key ="合格";
if("1".equals(sum.getStatus2())) key ="优秀";
else if("2".equals(sum.getStatus2())) key ="合格";
else if("3".equals(sum.getStatus2())) key ="基本合格";
else if("4".equals(sum.getStatus2())) key ="不合格";

// cell = new PdfPCell(new Paragraph(""+sum.getUser().getCname()+" 同志,在"+sum.getExam().getName()+"中,被评为 "+key,headFont));

Phrase myPhrase = new Phrase(12);
myPhrase.add(new Phrase(sum.getUser().getCname(), font1));
myPhrase.add(new Phrase(" 同志,在 ", font));
myPhrase.add(new Phrase(sum.getExam().getName().substring(0, 4)+"年度考核", font1));
myPhrase.add(new Phrase(" 中,被评为 ", font));
myPhrase.add(new Phrase(key, font1));
myPhrase.add(new Phrase(" 。", font));
cell = new PdfPCell(myPhrase);
cell.setBorderWidth(1.5f);
cell.setBorder(13);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell();
cell.setBorderWidth(1.5f);
cell.setBorder(14);
cell.setFixedHeight(40);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("年 \t月 \t日 ",headFont));
cell.setBorderWidth(1.5f);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.setBorder(14);
table.addCell(cell);

cell = new PdfPCell(new Paragraph("备注",headFont));
cell.setBorderWidth(1.5f);
cell.setFixedHeight(80);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(sum.getDescr(),headFont));
cell.setBorderWidth(1.5f);
table.addCell(cell);

document.add(table);
document.close();
response.setContentType("application/pdf");
response.setContentLength(ba.size());
ServletOutputStream out = response.getOutputStream();
ba.writeTo(out);
out.flush();

} catch (DocumentException de) {
System.err.println(de.getMessage());
return false;
}
catch (IOException ioe) {
System.err.println(ioe.getMessage());
return false;
}

return true;
}

阅读全文

与jsp页面打印表格相关的资料

热点内容
在哪里看电商销售数据 浏览:135
win10覆盖txt文件找回 浏览:556
哪个网站可以听高中的课 浏览:381
iphone5s查看文件夹 浏览:844
类似创客贴的app工具有哪些 浏览:81
苹果7手机型号怎么看 浏览:135
高通手机升级找不到那个文件 浏览:593
工程造价工资和软件编程哪个累 浏览:669
公考报名文件路径 浏览:988
人脸识别系统招标文件 浏览:260
阅读app20听书怎么设置 浏览:996
axure70教程视频下载 浏览:446
linux如何开启端口 浏览:474
盗版广联达能不能升级 浏览:368
qsb是什么文件格式 浏览:268
遍历ftp目录文件内容 浏览:612
求生之路22001升级2121 浏览:646
按键精灵如何检测没有网络后休眠 浏览:915
招标文件的内容应当符合标准 浏览:465
外推内插法c语言程序 浏览:146

友情链接