java jxl 导出excel,怎么用jxl实现导出Excel表,客户端可以导出并保存在自己电脑...

Java codepackage com.util;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.OutputStream;

import java.io.IOException;

import java.util.HashMap;

import java.util.Vector;

import javax.servlet.ServletContext;

import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import jxl.Workbook;

import jxl.WorkbookSettings;

import jxl.format.Colour;

import jxl.format.UnderlineStyle;

import jxl.read.biff.BiffException;

import jxl.write.Label;

import jxl.write.WritableFont;

import jxl.write.WritableWorkbook;

import jxl.write.WriteException;

import jxl.write.biff.RowsExceededException;

import com.xamedical.base.Prescription;

import com.xamedical.common.Format;

import com.xamedical.common.Globa;

import com.xamedical.common.UID;

import com.xamedical.system.District;

import com.xamedical.system.SysUserUnit;

import com.xamedical.system.SysPara;

import com.xamedical.system.Unit;

public class Excel {

private Globa globa;

private HttpServletRequest request;

private HttpServletResponse response;

private HttpSession session;

private ServletContext application;

public Excel(Globa globa) {

this.globa = globa;

this.request = globa.request;

this.response = globa.response;

this.session = globa.session;

this.application = globa.application;

}

public void output() {

String strFileId = UID.getID();

//File fExcel = new File(application.getRealPath("") + "\\excel\\" + strFileId + ".xls");

String filename = "方剂.xls"

try {

//输出

OutputStream os = response.getOutputStream();

response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1"));

response.setContentType("application/msexcel");

WritableWorkbook wwb = Workbook.createWorkbook(os);

jxl.write.WritableSheet ws = wwb.createSheet("复合查询结果", 0);

WritableFont wfSongBlack = new WritableFont(WritableFont.createFont("宋体"), 12, WritableFont.NO_BOLD,

false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);

jxl.write.WritableCellFormat wcfSongBlack = new jxl.write.WritableCellFormat(wfSongBlack);

//获取需要导出的方剂记录集合

Vector content = (Vector)session.getAttribute("content");

try {

Label l;

String composition;

String[] array;

for(int i=0;i

l = new Label(0,i,content.get(i).getStrName(),wcfSongBlack);

ws.addCell(l);

//分割方剂组成字符串,得到中药的一个字符串数组。

composition = content.get(i).getStrComposition();

composition = composition.replaceAll(",|。", "");

array = composition.split("\\d+g|.钱|.两");

for(int j=0;j

l = new Label(j+1,i,array[j],wcfSongBlack);

ws.addCell(l);

}

}

} catch(WriteException we) {

we.printStackTrace();

}

wwb.write();//写入excel对象

wwb.close();//关闭可写入的Excel对象

os.close();

}catch (IOException ioe) {

ioe.printStackTrace();

}

}

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值