[Tapestry5] t5 and poi 用 excel 进行数据的导入导出

sidang1hao 2008-01-29

Anyidea?,请共享下。

1 .export

 

1.1 java code

	public void onActionFromA(){
		int i = 0;
		HSSFWorkbook wb = new HSSFWorkbook();
		
		HSSFSheet sheet = wb.createSheet("sheet1");
		
		try {
		// 此处根据您具体情况定
	        ResultSet rs = getJdbcManager().executeQuery("select login,last_name from user_table");
	        while (rs.next()) {
	            HSSFRow row = sheet.createRow(i);
	            for(short j=1;j<3;j++){
	            	HSSFCell cell = row.createCell((short)(j-1));
	            	cell.setEncoding(HSSFCell.ENCODING_UTF_16);
	            	cell.setCellValue(rs.getString(j));	            	
	            }
	        }
	    } catch (SQLException e){
	        e.printStackTrace();
	    }
/*此处可以直接 inject response */

Response response = getResponse(); try{ OutputStream _out = response.getOutputStream("application/vnd.ms-excel"); //getResponse().getOutputStream("application/vnd.ms-excel"); wb.write(_out); _out.close(); }catch (Exception e) { // TODO: handle exception }

 

1.2 tml code

<t:actionLink t:id="a">aaaaaaaaa</t:actionLink>

 

1.3 maven dependency.

<!-- poi for xls  -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-contrib</artifactId>
      <version>3.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-scratchpad</artifactId>
      <version>3.0.2</version>
    </dependency>


1.4 dependencies classpath

 

..\.m2\repository\org\apache\poi\poi\3.0.2\poi-3.0.2-beta2-20080112.jar

另外两包

 

可以运行,tapestry 5.0.6

 

2 ,inport data ,any idea?




 

 

声动天下 2009-03-22
不够具体、、、
Global site tag (gtag.js) - Google Analytics