使用jxl处理Excel文件
Excel.jsp
<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <[email protected] import="java.io.*,jxl.*,jxl.write.*,jxl.write.*,jxl.format.*"%> <title>Insert title here</title> </head> <body> <% String path = "E://Eclipse//code__j2ee//JSPTest//WebRoot//resource//Excel.xls"; //Excel文件URL InputStream is = new FileInputStream(new File(path)); //写入到FileInputStream jxl.Workbook wb = Workbook.getWorkbook(is); //得到工作薄 jxl.Sheet st = wb.getSheet(0); //得到工作薄中的第一个工作表 %><br> <table width="200" border="1" bgcolor="#ff80ff" align="center"> <tbody> <% int line = st.getRows(); int colu = st.getColumns(); out.println(line + " " + colu); for (int i = 0; i < line; i++) { %> <tr> <% Cell cell[] = st.getRow(i); for (int j = 0; j < cell.length; j++) { //Cell cell = st.getCell(i, j); //得到工作表的第一个单元格,即A1 //String content = cell.getContents(); //getContents()将Cell中的字符转为字符串 String content = cell[j].getContents(); %> <td> <%=content%> </td> <% } %> </tr> <% } %> </tbody> </table> <% wb.close(); //关闭工作薄 is.close(); //关闭输入流 %> <br> </body> </html>
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/10441.html