資源簡介
該包內類實現了從數據庫查詢數據存到本地硬盤中格式為EXCEL,并且通過頁面下載該EXCEL,下載完畢后,刪除查詢的Excel文件。

代碼片段和文件信息
package?com.jiang.action;
import?java.io.*;
import?java.text.SimpleDateFormat;
import?java.util.List;
import?com.jiang.bean.Gm_Type;
import?com.jiang.dao.Gm_TypeDao;
import?jxl.*;
import?jxl.write.*;
import?jxl.write.Number;
public?class?CreateXLS?{
public?void?createXLS(List?list)?{
//?public?static?void?main(String?args[])?{
try?{
//?打開文件
WritableWorkbook?book?=?Workbook.createWorkbook(new?File(
“F:/upload/type.xls“));
//?生成名為“第一頁”的工作表,參數0表示這是第一頁
WritableSheet?sheet?=?book.createSheet(“第一頁“?0);
//?WritableSheet?sheet2?=?book.createSheet(“第二頁“?1);
//?在Label對象的構造子中指名單元格位置是第一列第一行(00)
//?以及單元格內容為test
//?Label?label=new?Label(00“test“);
//?將定義好的單元格添加到工作表中
//?sheet.addCell(label);
/*?生成一個保存數字的單元格?必須使用Number的完整包路徑,否則有語法歧義?單元格位置是第二列,第一行,值為789.123?*/
Label?label1?=?new?Label(0?0?“編號“);
Label?label2?=?new?Label(1?0?“名稱“);
Label?label3?=?new?Label(2?0?“狀態“);
Label?label4?=?new?Label(3?0?“時間“);
Label?label5?=?new?Label(4?0?“價格“);
sheet.addCell(label1);
sheet.addCell(label2);
sheet.addCell(label3);
sheet.addCell(label4);
sheet.addCell(label5);
SimpleDateFormat?sdf=new?SimpleDateFormat(“yyyy-MM-dd?HH:mm:ss“);
//System.out.println(“list大小“?+?list.size());
for?(int?i?=?0;?i? Gm_Type?gt?=?new?Gm_Type();
gt?=?(Gm_Type)?list.get(i);
Number?id?=?new?Number(0?i?+?1?gt.getId());
Label?name?=?new?Label(1?i?+?1?gt.getName());
Number?state?=?new?Number(2?i?+?1?gt.getState());
Label?insDate=new?Label(3i+1sdf.format(gt.getInsDate()));
Number?price?=?new?Number(4?i?+?1?gt.getPrice());
sheet.addCell(id);
sheet.addCell(name);
sheet.addCell(state);
sheet.addCell(insDate);
sheet.addCell(price);
}
//?寫入數據并關閉文件
book.write();
book.close();
}?catch?(Exception?e)?{
System.out.println(e);
}
}
public?static?void?main(String[]?args)?{
Gm_TypeDao?dao?=?new?Gm_TypeDao();
List?list?=?dao.selectType();
CreateXLS?xls?=?new?CreateXLS();
xls.createXLS(list);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????3412??2012-03-29?16:49??excel\.classpath
?????文件?????????288??2012-03-29?16:49??excel\.myme
?????文件????????1411??2012-03-29?16:49??excel\.project
?????文件?????????406??2012-03-29?16:49??excel\.settings\.jsdtscope
?????文件?????????116??2012-03-29?16:49??excel\.settings\org.eclipse.core.resources.prefs
?????文件?????????330??2012-03-29?16:49??excel\.settings\org.eclipse.jdt.core.prefs
?????文件??????????49??2012-03-29?16:49??excel\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2012-03-29?16:49??excel\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件??????????39??2012-03-29?16:49??excel\WebRoot\me
?????文件????????2788??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\action\CreateXLS.class
?????文件????????3009??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\action\FileDownServlet.class
?????文件????????1544??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\bean\Gm_Type.class
?????文件?????????577??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\dao\Gm_TypeDao.class
?????文件?????????665??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\ibatis\Gm_Type.xm
?????文件????????1390??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\ibatis\Sql-Map-Config.xm
?????文件????????6647??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\ibatis\SqlMapConn.class
?????文件????????1961??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\com\jiang\ibatis\databa
?????文件??????????49??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\webwork.properties
?????文件?????????901??2012-03-29?16:49??excel\WebRoot\WEB-INF\classes\xwork.xm
?????文件?????1521580??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\clover.jar
?????文件???????57779??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\commons-fileupload-1.2.1.jar
?????文件???????31909??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\commons-fileupload.jar
?????文件??????109043??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\commons-io-1.4.jar
?????文件???????45550??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\commons-io.jar
?????文件???????38015??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\commons-logging.jar
?????文件???????56404??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\cos.jar
?????文件???????36789??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\easymock.jar
?????文件????????5678??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\easymockclassextension.jar
?????文件??????789043??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\freemarker.jar
?????文件???????85038??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\ibatis-common-2.jar
?????文件???????59917??2012-03-29?16:49??excel\WebRoot\WEB-INF\lib\ibatis-dao-2.jar
............此處省略41個文件信息
- 上一篇:Java 1.5API 中文完整版卷1
- 下一篇:java多媒體技術彭波 孫一林
評論
共有 條評論