试试这个!把数据库取数据的换成你读取的信息!还需要jxl.jar包public class ExportExcelKmye extends HttpServlet { public ExportExcelKmye() {
super();
} public void destroy() {
super.destroy(); 

}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { try {
String exceldate = Tool.getActicleTime().substring(0, 10);
String sacct = request.getParameter("sacct");
String eacct = request.getParameter("eacct");
String date = request.getParameter("date");
String state = request.getParameter("state"); response.setContentType("APPLICATION/msexcel;charset=BIG5");
response
.setHeader("Content-Disposition", "attachment; filename="
+ new String("ヘ緇肂灿.xls".getBytes("BIG5"),
"ISO8859_1"));
OutputStream os = null;
try {
os = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
WritableWorkbook book = Workbook.createWorkbook(os);
WritableSheet sheet = book.createSheet("材", 0);
WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 15,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.GREEN);
WritableCellFormat headerFormat = new WritableCellFormat(headerFont); WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont); WritableFont detFont = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
WritableCellFormat detFormat = new WritableCellFormat(detFont); sheet.mergeCells(0, 0, 13, 0);// 虫じ
Label lable = new Label(
0,
0,
"                                                               ヘ緇肂灿 ",
headerFormat);
sheet.addCell(lable);
sheet.mergeCells(0, 1, 11, 0);
lable = new Label(0, 1, "ら戳:" + exceldate);
sheet.addCell(lable); // ︽糴砞竚
sheet.setColumnView(0, 15);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 12);
sheet.setColumnView(3, 15);
sheet.setColumnView(4, 35);
sheet.setColumnView(5, 12);
sheet.setColumnView(6, 15);
sheet.setColumnView(7, 15); lable = new Label(0, 3, "肚布ら戳", titleFormat);
sheet.addCell(lable);
lable = new Label(1, 3, "肚布絪腹", titleFormat);
sheet.addCell(lable);
lable = new Label(2, 3, "癸禜絪腹", titleFormat);
sheet.addCell(lable);
lable = new Label(3, 3, "癸禜嘿", titleFormat);
sheet.addCell(lable);
lable = new Label(4, 3, "篕璶", titleFormat);
sheet.addCell(lable);
lable = new Label(5, 3, "肂", titleFormat);
sheet.addCell(lable);
lable = new Label(6, 3, "肂璸", titleFormat);
sheet.addCell(lable);
ResultSet rs = DbUtil.exeQuery("exec dbo.Gl_EndDetail  @Day = '"
+ date + "', @AcctNo1 = '" + sacct + "', @AcctNo2 = '"
+ eacct + "'");
float f1=0.0f;
int k = 4;
          while (rs!=null&&rs.next()) {
            float nt_tot=rs.getFloat("nt_tot");
            f1+=nt_tot;
lable = new Label(0, k,Tool.deNull(rs.getString("voc_dat")),detFormat);
sheet.addCell(lable);
lable = new Label(1, k,Tool.deNull(rs.getString("voc_no")), detFormat);
sheet.addCell(lable);
lable = new Label(2, k,Tool.deNull(rs.getString("cus_no")), detFormat);
sheet.addCell(lable);
lable = new Label(3, k,Tool.deNull(rs.getString("cus_nam")), detFormat);
sheet.addCell(lable);
lable = new Label(4, k,Tool.deNull(rs.getString("memoa")), detFormat);
sheet.addCell(lable);
lable = new Label(5, k,Tool.changeCash(rs.getFloat("ntac_amt")), detFormat);
sheet.addCell(lable);
lable = new Label(6, k,Tool.changeCash(nt_tot), detFormat);
sheet.addCell(lable);
k++;
}
sheet.mergeCells(0, k + 1,6, 0);
lable = new Label(0, k + 1, "璸肂 "+ Tool.changeCash(f1), detFormat);
sheet.addCell(lable);
book.write();
book.close();
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
} public void init() throws ServletException {

}}

解决方案 »

  1.   

    我汗!忘记改!以前的是BIG5!你改成gbk或者gb2312
      

  2.   

    我已经解决了
    汉字显示为乱码问题  
    是因为编码格式设置的时候产生了错误
    应该是cell.setEconding()
    而不是row.creatCell().setEconding()
    定位到9行  其实我一直是新建新workbook当然会覆盖已经存在的表头了
    其实只要用已经存在的EXCEL表格做工作区间就不会由这个问题了
    空格不用令牌化字符串 而用split()更好用!
    总之还是感谢2楼  
    给你加分吧!