❶ 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;
}