java 导出excel乱码_java使用poi或jxl导出excel乱码

public static void exportExcel(ListdataList, String filename, OutputStream out){/*try {

//读取模板

InputStream in = new FileInputStream("C:\\Users\\yinbx\\IdeaProjects\\JCogent\\cogent-common\\src\\main\\java\\com\\cogent\\template\\cure_plans.xls");

//通过模板创建工作簿

HSSFWorkbook wb = new HSSFWorkbook(in);

//获取shell

HSSFSheet sheet = wb.getSheetAt(0);

//获取模板的内容

HSSFRow Trow = sheet.getRow(2);

int i=3;

HSSFRow row = null;

HSSFCell cell = null;

for (Map map: dataList) {//遍历数据集填充到excel

row = sheet.createRow(i);

for(int j=0; j

cell = row.createCell((short)j);

//cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell.setCellValue(map.get(Trow.getCell(j).getStringCellValue()).toString());

}

i++;

}

wb.write(out);

out.close();

}catch (IOException e){

System.out.println("文件流异常");

e.printStackTrace();

}*/

try{

WorkbookSettings settings= newWorkbookSettings();

settings.setWriteAccess(null);

settings.setEncoding("UTF-8");

Workbook wb= Workbook.getWorkbook(new File("C:\\Users\\yinbx\\IdeaProjects\\JCogent\\cogent-common\\src\\main\\java\\com\\cogent\\template\\cure_plans.xls"));

WritableWorkbook wwb=Workbook.createWorkbook(out, wb,settings);

WritableSheet sheet= wwb.getSheet(0);int i =3;

Label label;for(Map map : dataList){for(int j =0; j

label=new Label(j,i,map.get(sheet.getCell(j,2).getContents()).toString());

sheet.addCell(label);

}

i++;

}

wwb.write();

wwb.close();

}catch(IOException e) {

e.printStackTrace();

}catch(BiffException e) {

e.printStackTrace();

}catch(RowsExceededException e) {

e.printStackTrace();

}catch(WriteException e) {

e.printStackTrace();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值