excel 导出文件名乱码 您所在的位置:网站首页 java导出excel表格是乱码应该怎样解决 excel 导出文件名乱码

excel 导出文件名乱码

2023-02-28 07:05| 来源: 网络整理| 查看: 265

 因为经常要用到导出功能,之前因为文件名乱码,所以都用英文或是拼音缩写来代替,今天特意要接觉下这个问题。顺便记录下。望对小白有用。

/**

     * 导出结算详情列表

     * @return

     */

public void  depositLogExport()

    {

    String title = "押金流水报表";

String excelName = "押金流水报表.xls";

OutputStream os = null;

        try

        {

       

        int shopId=new Long(getShopLoginer().getShop().getId()).intValue();

        if(date==null){

        date=new DateBean();

        }

        int count=service.getCount(shopId, date);

        Page pageResult =new Page();

        if(count>0){

        pageResult = service.list(1, count, shopId, date);

        }

           

            List list = new ArrayList();

           double shopDeposit=getShopLoginer().getShop().getDeposit();

            for (DepositLog s : pageResult.getData())

            {

                Map map = new HashMap();

                map.put("id", s.getId());

                map.put("depositSn", s.getDepositSn());

                map.put("createTime",                     StringUtils.timestampToString(s.getCreateTime()));

                map.put("type", type[s.getType()]);

                map.put("amount", s.getAmount());

                map.put("depositRest", s.getDepositRest());

                map.put("depositGap", shopDeposit-s.getDepositRest());

                map.put("userName", s.getUserName());

                map.put("remarks", s.getRemarks());

                list.add(map);

            }

      

// 表格表头

String[] header = {"流水号","流水时间","类型","流水金额","押金余额","押金缺口","操作人","备注"};

// 对应Map中的key

String[] key = { "depositSn", "createTime","type",

"amount", "depositRest", "depositGap", "userName", "remarks"};

HSSFWorkbook workbook = null;

HttpServletResponse response = ServletActionContext

.getResponse();

workbook = ExportUtil.workPaperExport(list, header, key,

title, true, null, null, null);

os = response.getOutputStream();

response.setHeader("Content-disposition",

"p_w_upload; filename=" + toUtf8String(excelName));

response.setContentType("application/msexcel;");

workbook.write(os);

os.flush();

     

} catch (Exception e) {

if (logger.isDebugEnabled())

logger.error(e.getMessage(), e);

e.printStackTrace();

} finally {

try {

if (os != null)

os.close();

} catch (IOException e) {

if (logger.isInfoEnabled())

logger.error(e.getMessage(), e);

e.printStackTrace();

}

}

//return null;

}

//文件名乱码处理

 public static String toUtf8String(String s){ 

    StringBuffer sb = new StringBuffer(); 

      for (int i=0;i= 0 && c



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有