jxl读excel中数据的问题{全部家当酬谢}
本菜鸟用jxl读excel中数据时出现问题。
运行后什么错误提示都没有,但就是得不到输出,页面是空的,白纸一张。恳请高手给予解答!
我的测试页面代码如下:
<%@ page contentType= "text/html; charset=gb2312 "%>
<%@ page import= "java.util.* " %>
<%@ page import= "java.io.* " %>
<%@ page import= "jxl.* " %>
<%@ page import= "jxl.write.* " %>
<%@ page import= "jxl.format.* " %>
<html>
<head>
<title> </title>
</head>
<body>
<%
InputStream is = new FileInputStream( "D:\\test.xls ");
jxl.Workbook wb = Workbook.getWorkbook(is);
jxl.Sheet st = wb.getSheet(0);//得到工作薄中的第一个工作表
int rsRows = st.getRows(); //得到excel的总行数
for (int i = 1; i < rsRows; i++) {
Cell cell0 = st.getCell(0, i);//得到工作表的第一个单元格,即A1
Cell cell1 = st.getCell(1, i);//得到工作表的第二个单元格,即A1
try {
String content0 = cell0.getContents();
String content1 = cell1.getContents();
//输出数据
out.println(content0);
out.println(content1);
} catch (Exception e) {
//如果EXCEL文件中输入的数据有错,则跳过此行数据
session.setAttribute( "message ", "hello ");
continue;
}
}
wb.close();
is.close();
%>
</body>
</html>
------解决方案--------------------应该是common\lib下.
你可以给页面指定
errorPage 应该知道了.
或者在Tomcat运行的时候,看看里面有没有异常可以知道.
------解决方案--------------------这是用poi写的自己参考下。
PrintWriter out = response.getWriter();
String action=request.getParameter( "action ");
if( "excel ".equals(action)) {
List list=(List)request.getSession().getAttribute( "list ");
String fileName = "入库明细台帐.xls ";
String path = request.getRealPath( " ");
path = path + "/page/rcjc/excel ";
File f = new File(path, fileName);
WritableWorkbook book = Workbook.createWorkbook(f);
sheet = book.createSheet( "入库明细台帐 ", 0);
sheet.setColumnView(0, 20);
sheet.setColumnView(1, 50);
WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD,false,
UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat headerFormat = new WritableCellFormat(headerFont);
try {
sheet.mergeCells(3,0,6,1);
sheet.addCell(new Label(3,0, "入 库 明 细 台 帐 ",headerFormat));
sheet.mergeCells(2,2,3,2);
sheet.addCell(new Label(2,2, "检查单位: "));
sheet.mergeCells(4,2,7,2);
sheet.mergeCells(9,2,10,2);
sheet.addCell(new Label(9,2, "单位:万元 "));
sheet.addCell(new La