JSP页面导出CSV查询结果

这个很多网站都有,找了一个,感觉好用:

StringqueryResult= ...;
response.setContentType(
"application/csv" );
response.setHeader(
"Content-Disposition","inline;filename="result.csv"" );
PrintWriterout
=newPrintWriter(new OutputStreamWriter(
response.getOutputStream(),
"UTF-8" ));
out.print(queryResult);
out.close();

但我自己在做的时候遇到一个实际问题,因为我要导出的结果中有时间,它的格式是这样的2007-09-01 07:00:00,用notepad打开的话肯定没问题,但如果用excel打开就有点问题了,时间段会变成####,因为excel的时间格式是01/09/2007 07:00:00。所以要在导出前处理下这个string。

private static final DateFormatformatVLS = new SimpleDateFormat( " yyyy-MM-ddHH:mm " );
private static final DateFormatformatCSV = new SimpleDateFormat( " dd/MM/yyyyHH:mm " );

private StringconvertTimeForCSV(Stringinput) throws VLSException ... {
try...{
returnformatCSV.format(formatVLS.parse(input));
}
catch(ParseExceptione)...{
//TODOAuto-generatedcatchblock
thrownewVLSException(VLSConstants.ERROR_FORMAT);
}

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值