- 浏览: 48382 次
- 性别:
- 来自: 大连
最近访客 更多访客>>
最新评论
-
wildeurope:
楼主代码 看起来很乱 不过还是有实用性的 借鉴下
java导出Excel 玩玩吧! -
evanz:
这个只能打word中的文字吧,图片应该是不能打得
java打印word的分享 -
xin163:
不是一般人谁能看懂?
java导出Excel 玩玩吧! -
lerous:
包提供的还不错````至于代码`?````
java导出Excel 玩玩吧! -
jiyuchonger:
很垃圾。。。
java导出Excel 玩玩吧!
java 代码
- /*
- * Generated by MyEclipse Struts
- * Template path: templates/java/JavaClass.vtl
- */
- package com.axon.fable.sams.view.action;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import jxl.Workbook;
- import jxl.write.WriteException;
- import jxl.write.biff.RowsExceededException;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.hibernate.HibernateException;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import com.axon.fable.empolderpackage.out.OutJavaScript;
- import com.axon.fable.empolderpackage.page.Pager;
- import com.axon.fable.empolderpackage.string.MyPublic;
- import com.axon.fable.sams.common.BaseAction;
- import com.axon.fable.sams.exception.AppBusinessException;
- import com.axon.fable.sams.exception.AppSystemException;
- /**
- * MyEclipse Struts
- * Creation date: 06-28-2007
- *
- * XDoclet definition:
- * @struts.action path="/axon" name="axonForm" input="/samspage/zm/axon.jsp" parameter="method" scope="request" validate="true"
- * @struts.action-forward name="success" path="/samspage/zm/content.jsp"
- */
- public class StshipoperationAction extends BaseAction {
- /*
- * Generated Methods
- */
- private static Session session=null;
- private static Transaction ts=null;
- private static Query queryC=null;
- private static Query queryR=null;
- private static Query query=null;
- private static List list=null;
- private static Integer startRow;
- private static Integer ncurrentPage;
- private static Integer cell;
- private static String property;
- private static String sql;
- private static String type;
- private static String condition ;//是否导出当前页
- private static String currentPage;
- private static String from ;
- private static String pactdata;
- private static String voyagename;
- private static String voyageno;
- private static String dwt ;
- private static String hirefrom ;
- private static String deliveryposion ;
- private static String redeliveryposion ;
- private static String sheepowner ;
- private static String addr;
- private static String addcomm;
- private static String rent;
- private static String fileName ;
- private static OutputStream os;
- @Override
- public ActionForward findAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public ActionForward findById(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
- // TODO Auto-generated method stub
- return null;
- }
- public static String strNull(Object nullStr,String newStr,Integer cell){
- if(nullStr==null||nullStr.equals("")){return newStr;}else{cell+=1;return nullStr+"";}
- }
- public static String getStr(String str,Integer cell){
- if(str==null||str.trim().equals("")){return "";}else{cell+=1;return ","+str;}
- }
- public static String getExcelTile(String title){
- if(title==null)
- return "";
- if(title.equals("modela.stsid"))
- return "编号";
- if(title.equals("modelc.pactdata"))
- return "合同日期";
- if(title.equals("modela.voyagename"))
- return "航名";
- if(title.equals("modela.voyageno"))
- return "航次";
- if(title.equals("modelc.dwt"))
- return "DWT";
- if(title.equals("modelc.hirefrom"))
- return "受载期";
- if(title.equals("modela.deliveryposion"))
- return "交船地点";
- if(title.equals("modela.redeliveryposion"))
- return "还船地点";
- if(title.equals("modelc.sheepowner"))
- return "联系人";
- if(title.equals("modelc.addr"))
- return "经纪人拥金";
- if(title.equals("modelc.addcomm"))
- return "ADD COMM";
- if(title.equals("modelc.rent"))
- return "租金";
- return "";
- }
- public ActionForward exporVoyagesInfoToExcel(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- list=null;
- startRow=0;
- ncurrentPage=1;
- cell=0;
- type =request.getParameter("type");
- condition =request.getParameter("condition");//是否导出当前页
- currentPage =request.getParameter("currentPage");
- from =request.getParameter("from");
- pactdata = request.getParameter("modelc.pactdata");
- voyagename = request.getParameter("modela.voyagename");
- voyageno = request.getParameter("modela.voyageno");
- dwt = request.getParameter("modelc.dwt");
- hirefrom = request.getParameter("modelc.hirefrom");
- deliveryposion = request.getParameter("modela.deliveryposion");
- redeliveryposion = request.getParameter("modela.redeliveryposion");
- sheepowner = request.getParameter("modelc.sheepowner");
- addr = request.getParameter("modelc.addr");
- addcomm = request.getParameter("modelc.addcomm");
- rent = request.getParameter("modelc.rent");
- if(type!=null&&type.trim().equals("1")){
- type ="已还船舶--费用未结清";
- }else{
- type ="已还船舶--费用已结清";
- }
- property =getStr(pactdata,cell)+getStr(voyagename,cell)+getStr(voyageno,cell)+getStr(dwt,cell)+getStr(hirefrom,cell)
- +getStr(deliveryposion,cell)+getStr(redeliveryposion,cell)+getStr(sheepowner,cell)+getStr(addr,cell)+getStr(addcomm,cell)
- +getStr(rent,cell);
- property = property.substring(1);
- String split[] = property.split(",");
- // System.out.println("-----------------------------property:"+property);
- if(currentPage!=null&&!currentPage.trim().equals("")){
- ncurrentPage =Integer.parseInt(currentPage);
- }else{
- OutJavaScript.outString(response, "Sorry! Failed to get information of pager.");
- return null;
- }
- try {
- session =getServiceLocator().getBaseHibernateDAO().getSession();
- sql ="select count(*) "+from;
- query =session.createQuery(sql);
- list = query.list();
- for (int i = 0; i < list.size(); i++) {
- totalSize =(Integer)list.get(i);
- if(totalSize!=0){
- pager =new Pager(ncurrentPage,totalSize);
- }
- }
- query =getServiceLocator().getBaseHibernateDAO().getSession().createQuery("select " +property+from);
- if(condition!=null&&condition.trim().equals("1")){//分页数据
- startRow = (ncurrentPage - 1)*pager.getPageSize();
- query.setFirstResult(startRow);
- query.setMaxResults(pager.getPageSize());
- // System.out.println("---------------------------------------------------query:"+query);
- }
- list = query.list();
- fileName = "shipInfo";
- os = response.getOutputStream();
- response.reset();
- response.setHeader("Content-disposition",
- "attachment; filename=" +fileName + ".xls");
- response.setContentType("application/msexcel");
- jxl.write.WritableWorkbook wbook = Workbook.createWorkbook(os);
- jxl.write.WritableSheet wsheet = wbook.createSheet("the first sheet", 0);
- for (int i = 0; i < split.length; i++) {
- jxl.write.Label wlabel0;
- wlabel0 = new jxl.write.Label(i, 0, getExcelTile(split[i]));
- wsheet.addCell(wlabel0);
- }
- jxl.write.Label wlabel1;
- for(int i=0;i<list.size();i++) {
- if(split.length==1){
- Object strval = (Object) list.get(i);
- String javaScript=""+MyPublic.toHtmlStr(strval==null?"":strval.toString().trim())+"";
- wlabel1 = new jxl.write.Label(0, i+1,strval==null?"":strval.toString().trim() );
- wsheet.addCell(wlabel1);
- }else{
- Object[] strval = (Object[]) list.get(i);
- for(int j=0;j<strval.length;j++) {
- String javaScript=""+MyPublic.toHtmlStr(strval[j]==null?"":strval[j].toString().trim())+"";
- //System.out.println("===================script:"+javaScript);
- wlabel1 = new jxl.write.Label(j, i+1,strval[j]==null?"":strval[j].toString().trim() );
- wsheet.addCell(wlabel1);
- }
- }
- }
- wbook.write();
- response.flushBuffer();
- wbook.close();
- os.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! Export Excel exception.");
- e.printStackTrace();
- } catch (HibernateException e1) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! Database exception.");
- e1.printStackTrace();
- } catch (AppSystemException e1) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! System exception.");
- e1.printStackTrace();
- } catch (AppBusinessException e1) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! Database exception.");
- e1.printStackTrace();
- } catch (RowsExceededException e) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! Export Excel exception.");
- e.printStackTrace();
- } catch (WriteException e) {
- // TODO Auto-generated catch block
- OutJavaScript.outString(response, "Sorry! Export Excel exception.");
- e.printStackTrace();
- }
- return null;
- }
- @Override
- public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
- // TODO Auto-generated method stub
- return null;
- }
- }
- jxl.jar (499.4 KB)
- 描述: 需用到的Excel包
- 下载次数: 492
评论
5 楼
wildeurope
2009-08-18
楼主代码 看起来很乱 不过还是有实用性的 借鉴下
4 楼
xin163
2008-12-17
不是一般人谁能看懂?
3 楼
lerous
2008-10-10
包提供的还不错````至于代码`?````
2 楼
jiyuchonger
2008-10-04
很垃圾。。。
1 楼
ralfsumahe
2008-06-02
头晕
发表评论
-
常用的文件操作方法
2007-12-08 15:22 1451java 代码 import ja ... -
对xml文档操作的常用方法
2007-12-08 15:19 1478java 代码 import ja ... -
操作excel文件,从文件中读取数据。
2007-12-08 15:14 1889java 代码 import or ... -
Subversion之路---实现精细的目录访问权限控制(转载)
2007-11-02 09:34 19681.1 Subversion 权限简介在 ... -
freemarker+velocity+jsf+spring+hibernate 初探一
2007-09-20 19:21 2605喜欢架构方面的东西,在一年多以前就开始接触freem ... -
java打印word的分享
2007-09-08 13:09 4264大有有兴趣,下来玩玩吧! 有心得多分享哦! -
少走弯路的十条忠告
2007-09-08 12:52 828如何在涉世之初少走弯路,有一个好的开端,开始一番成功的事业? ... -
OutJavaScript
2007-09-03 20:43 1224java 代码 package com.axon ... -
程序中调用批处理执行Mysql数据库导入导出
2007-09-03 20:39 1933/** * @param cmdStr ... -
hibernate配置
2007-09-03 20:35 814"-//Hibernate/ ... -
struts+hibernate+spring+FreeMarker 2
2007-09-01 21:03 1540自动生成几个文件: 并且,spring的applic ... -
struts+hibernate+spring+FreeMarker
2007-09-01 21:00 921这几天把hibernate和spring好好看了下,再想想st ...
相关推荐
总的来说,"poi操作excel的jar包集.rar"为Java开发者提供了一整套处理Excel文件的工具,无论你是需要进行数据导入导出、报表生成,还是自动化测试,这个库都能满足你的需求。只需熟练掌握Apache POI的API,就能在...
这款软件尤其适用于那些喜欢玩国际版或者非中文版本Java游戏的用户。 在Java平台上,游戏通常由一系列的.class文件和.jar文件组成,这些文件包含了游戏的代码、资源和逻辑。MobiTrans汉化工具能够深入这些文件,...
MiniExcel具有高度的扩展性和灵活性,使得开发者在进行大数据量的Excel导入导出时,能更加高效且稳定。 1. **内存优化与性能提升**: MiniExcel 在处理大数据时,通过流式处理和分块读写的方式,减少了内存占用,...
7. 文件操作:除了读取Excel文件,应用可能还支持导出分析结果至Excel或其他格式,方便用户进一步处理或分享。 8. 性能优化:由于可能需要处理大量数据,应用程序可能采用了优化算法以提高计算效率,如使用并行计算...
2009-03-09 09:38 132723 34712 常见的专业问题解决办法\百度_网盾工程吧_MySQL导出导入命令.mht 2003-06-20 20:49 153581 146314 常见的专业问题解决办法\精通swing程序设计.chm 2009-02-26 16:33 177152 37861 ...
(21)\SQL课程素材软件下载\SQL素材下载\第三章 数Ju库工具\SQL server 2008\导出学生管理文件;目录中文件数:4个 ├─(75) course.csv ├─(76) SC.csv ├─(77) student.csv ├─(78) xuesheng.xlsx (22)\SQL...
1. **数据录入**:系统应该能够方便地输入学生的个人信息,如姓名、班级、学号等,同时支持快速录入、批量导入或导出成绩。 2. **成绩管理**:系统应提供一个界面,允许教师录入、修改和查看学生的考试、作业、项目...