日期:2014-05-20 浏览次数:20855 次
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public void exportExcelFile() {
try {
HttpServletResponse response = ServletActionContext.getResponse();
String fileName = Long.toString(System.currentTimeMillis())+".xls";
OutputStream os = response.getOutputStream();// 取得输出流
response.reset();// 清空输出流
response.setHeader("Content-disposition", "attachment; filename="
+ fileName);// 设定输出文件头
response.setContentType("application/msexcel");// 定义输出类型
ResourceMgt
.addDefaultResourceBundle("com.zte.cnt_manager_resource");
String title = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.title");
WritableWorkbook wbook = Workbook.createWorkbook(os); // 建立excel文件
String tmptitle = title; // 标题
WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
// 设置excel标题
WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.BLACK);
WritableCellFormat wcfFC = new WritableCellFormat(wfont);
wcfFC.setBackground(Colour.AQUA);
wsheet.addCell(new Label(1, 0, tmptitle, wcfFC));
// 读取资源文件,获得excel的第一行文字内容。
String cntid = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.cntid");
String cntname = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.cntname");
String catname = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.catname");
String cntcreatetime = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.cntcreatetime");
String truename = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.truename");
String statusname = ResourceMgt
.findDefaultText("cnt.expexcel.cntmanager.status");
// 生成excel 第一行数据。
wsheet.addCell(new Label(0, 0, cntid));
wsheet.addCell(new Label(1, 0, cntname));
wsheet.addCell(new Label(2, 0, catname));
wsheet.addCell(new Label(3, 0, cntcreatetime));
wsheet.addCell(new Label(4, 0, truename));
wsheet.addCell(new Label(5, 0, statusname));
// 导出的excel主体 数据内容。
mcntContentExtends.setApplytimestart(mcntContentExtends
.getApplytimestart());
mcntContentExtends.setApplytimeend(mcntContentExtends
.getApplytimeend());
// 对导出的数据 排序。
PageUtilEntity puEntity = new PageUtilEntity();
puEntity.setOrderByColumn("applytime");
puEntity.setIsAsc(false);
MsysConfig msysConfig = new MsysConfig();