csv文件生成

/**
 * 生成csv文件
 * @param data  要写入文件的内容
 * @param path  文件要保存的路径
 */
public static void CreateCSV(ArrayList<ArrayList<String>> data, String path) {
    BufferedWriter out = null;
    long start = System.currentTimeMillis();
    try {
        out =new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path),"GBK"));
        //表头信息写入
        ArrayList<String> titleHeader = new ArrayList<>(Arrays.asList("会员号", "会员昵称", "推客等级","直推","引导消费者","消费额", "推广订单额", "佣金"));
        for(int i = 0; i < titleHeader.size(); i++){
            out.write(titleHeader.get(i));
            out.write(",");
        }
        out.newLine();
        //换行后写入文件内容
        for (int i = 0; i < data.size(); i++) {
            ArrayList<String> onerow = data.get(i);
            for (int j = 0; j < onerow.size(); j++) {
                out.write(onerow.get(j));
                out.write(",");
            }
            out.newLine();
        }
        out.flush();
        long end = System.currentTimeMillis();
        logger.info("报表生成完毕,用时: " + (end - start) + " ms");
    } catch (Exception e) {
        logger.error("写文件异常");
        logger.error(e.getMessage(), e);
    }finally {
        try {
            if(out != null){
                out.close();
            }
        } catch (IOException e) {
            logger.error("关闭数据写出流异常");
            logger.error(e.getMessage(), e);
        }
    }
}

public static String DelQuota(String str) {
    String result = str;
    String[] strQuota = { "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "`", ";", "'", ",", ".", "/", ":", "/,", "<", ">", "?" };
    for (int i = 0; i < strQuota.length; i++)
    {
        if (result.indexOf(strQuota[i]) > -1)
            result = result.replace(strQuota[i], "");
    }
    return result;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值