java生成日报表代码 java生成表格

java导出exceljava导出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.serv ...
java导出Excel例举方式
方法一java生成日报表代码:导出Excel数据的插件jexcelapi
程序实例如下java生成日报表代码:
public void exportClassroom(OutputStream os) throws PaikeException {
try {
WritableWorkbook wbook = Workbook.createWorkbook(os); //建立excel文件
WritableSheet wsheet = wbook.createSheet("教室信息表", 0); //工作表名称
//设置Excel字体
WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,
WritableFont.BOLD, false,
jxl.format.UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(wfont);
String[] title = { "教室名", "容 量", "类 型", "其java生成日报表代码他说明" };
//设置Excel表头
for (int i = 0; ititle.length; i++) {
Label excelTitle = new Label(i, 0, title[i], titleFormat);
wsheet.addCell(excelTitle);
}
int c = 1; //用于循环时Excel的行号
ClassroomService cs = new ClassroomService();
List list = cs.findAllClassroom(); //这个是从数据库中取得要导出的数据
Iterator it = list.iterator();
while (it.hasNext()) {
ClassroomDTO crdto = (ClassroomDTO) it.next();
Label content1 = new Label(0, c, crdto.getRoomname());
Label content2 = new Label(1, c, crdto.getCapicity().toString());
Label content3 = new Label(2, c, crdto.getRoomTypeId()
.toString());
Label content4 = new Label(3, c, crdto.getRemark());
wsheet.addCell(content1);
wsheet.addCell(content2);
wsheet.addCell(content3);
wsheet.addCell(content4);
c++;
}
wbook.write(); //写入文件
wbook.close();
os.close();
} catch (Exception e) {
throw new PaikeException("导出文件出错");
}
}
方法二java生成日报表代码:直接用Java代码实现导出Excel报表
/*
* 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;

推荐阅读