写了,以下代码,不知道为什么,写进excel中的中文就变成了乱码 public static void main(String[] args) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("work1");
HSSFRow row = worksheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellStyle(workbook.createCellStyle());
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("你好");
row = worksheet.createRow(1);
cell = row.createCell((short) 0);
cell.setCellValue("热烈欢迎");
try {
FileOutputStream fos = new FileOutputStream("c:/t.xls");
workbook.write(fos);
fos.flush();
fos.close();
System.out.println("----------------生成完毕");
} catch (Exception ex) {
ex.printStackTrace();
} }
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("work1");
HSSFRow row = worksheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellStyle(workbook.createCellStyle());
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("你好");
row = worksheet.createRow(1);
cell = row.createCell((short) 0);
cell.setCellValue("热烈欢迎");
try {
FileOutputStream fos = new FileOutputStream("c:/t.xls");
workbook.write(fos);
fos.flush();
fos.close();
System.out.println("----------------生成完毕");
} catch (Exception ex) {
ex.printStackTrace();
} }
解决方案 »
- mySmartUpload插件乱码问题
- httpSlient post数据后,接收数据的网页会自动刷新吗?
- ie后退按钮脚本怎么写??
- 百分求 精通Struts:基于MVC的JavaWeb设计与开发(孙卫琴) 的源代码
- 我的TOMCAT有问题了~ 重装系统都不行了~!5.5.12的
- jsf问题
- jsp中可以远程读取.jsp文件生成html文件的函数是什么
- 一个月之前做的主页,欢迎大家评论(来者有分)
- zxhong(红)请进
- jboss部署
- 使用动态表单出现的异常:javax.servlet.ServletException: Exception creating bean of class org.apache.struts.action.DynaActionForm
- ★jsp 如何读取 html控件的值??在线等
三楼的,你说的那个是在什么地方设
font.setFontName("SimSun"); //宋体
HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
HSSFCell cell = queryHeaderRow.createCell((short)0);
cell.setCellStyle(style);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = null;String[] title = {"部门", "工号", "姓名", "类型", "初始值", "已使用", "当前值"};
for (int i = 0; i < title.length; i++) {
cell = row.createCell((short) i);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(title[i]);
}
List list = Holiday.query(conn, this.orgcode, this.stuffID, this.stuffName, this.stuffKind, this.year);
for(int i=0;i<list.size();i++){
Map map = (Map)list.get(i);
row = sheet.createRow((short) i + 1); cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("orgname")==null?"":map.get("orgname").toString()); cell = row.createCell((short) 1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("stuffid")==null?"":map.get("stuffid").toString()); cell = row.createCell((short) 2);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("name").toString()); cell = row.createCell((short) 3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("type")==null?"":map.get("type").toString()); cell = row.createCell((short) 4);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("initial_value")==null?"":map.get("initial_value").toString()); cell = row.createCell((short) 5);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("kc_value")==null?"":map.get("kc_value").toString()); cell = row.createCell((short) 6);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setEncoding(cell.ENCODING_UTF_16);
cell.setCellValue(map.get("current_value")==null?"":map.get("current_value").toString());
}this.getResponse().reset();
this.getResponse().setContentType("text/plain;charset=UTF-8"); // UTF-8
this.getResponse().setBufferSize(1024 * 1024 * 10);
this.getResponse().setHeader("Content-Disposition", "attachment;filename=holiday.xls");
ServletOutputStream out = this.getResponse().getOutputStream();
workbook.write(out);
out.flush();我的代码片段。