csv文件中,解决数字列转换成文本列
2011-05-10 13:18阅读:
在csv文件导出的处理中,对每一列的数据都增加引号和水平制表符。这样在使用Excel打开导出后的文件时,数字字段将会被当成文本字段处理。
buffer.append('\'\t'+list.get(i).getSmdbh() + '\',\'\t' +
qysh + '\',' + qymc + ',' + lxqymc + ',' + list.get(i).getYwmc() +
','
+ smlx +',' + smzt +','+
smry + ','+smjg+',' + kdry + ','
+ sjsmry + ',' + ddsj + ','
+ lksj + ',' + wcqk + ',' + myd + ',' + hfqksm + ',' + bz +
',' + lxrdz + ','+smxs+'');
System.out.println(buffer.toString());
response.setContentLength(buffer.toString().getBytes().length);
response.setContentType('application/csv;charset=GB2312');
String fileName = 'list.csv';
response.addHeader('Content-Disposition',
'attachment;filename=' + fileName);
response.setCharacterEncoding('GB2312');
response.getOutputStream().write(buffer.toString().getBytes('GB2312'));
response.
getOutputStream().flush();