jsp页面显示数据导出到excel表中__教程 |
|
日期:2007-5-9 18:52:55 人气:142 [大 中 小] |
|
|
|
case HSSFCell.CELL_TYPE_STRING: out.print( cell.getStringCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: out.print(cell.getNumericCellValue()); //读出公式储存格计算後的值 //若要读出公式内容,可用cell.getCellFormula() break; default: out.print( "不明的格式"); break; } out.println("</td>"); } out.println("</tr>"); } %> </table> </body> </html> 五、资料新增範例 <%@ page contentType="text/html;charset=MS950" import="java.util.*,java.io.*" %> <%@ page import="org.apache.poi.poifs.filesystem.*,org.apache.poi.hssf.usermodel.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=MS950"> <title>插入资料至Excel档案</title> </head> <body> <% FileInputStream finput = new FileInputStream(application.getRealPath("/")+"book1.xls" ); //设定FileINputStream读取Excel档 POIFSFileSystem fs = new POIFSFileSystem( finput ); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); //读取第一个工作表,宣告其为sheet finput.close(); HSSFRow row=null; //宣告一列 HSSFCell cell=null; //宣告一个储存格 short i=4; row=sheet.createRow(i); //建立一个新的列,注意是第五列(列及储存格都是从0起算) cell=row.createCell((short)0); cell.setEncoding(HSSFCell.ENCODING_UTF_16); //设定这个储存格的字串要储存双位元 cell.setCellValue("显示卡"); cell=row.createCell((short)1); cell.setCellValue(1700); cell=row.createCell((short)2); cell.setCellValue(8); cell=row.createCell((short)3); //设定这个储存格为公式储存格,并输入公式 cell.setCellFormula("B"+(i+1)+"*C"+(i+1)); try { FileOutputStream fout=new FileOutputStream(application.getRealPath("/")+"book1.xls"); wb.write(fout); //储存 |
|
出处:本站原创 作者:佚名 |
|
|