Dataset如何写成csv文件
想请教一下,如何将RFT中连接数据库获得的Dataset写成csv文件 public static boolean createCsv(HttpServletResponse Response, QueryData qryData, String[][] columnName) throws Exception{
String data = "";
SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmm");
Date today = new Date();
String dateToday = dataFormat.format(today);
if (qryData.size() == 0 || columnName.length == 0)
return false;
data += "编号,";
for (int i = 0; i < columnName.length; i++)
{
data += columnName + ",";
}
data += "\n";
for (int i = 0; i < qryData.size(); i++)
{
data += String.valueOf(i + 1) + ",";
for (int j = 0; j < columnName.length; j++)
{
data += qryData.getRow(i).get(columnName) + ",";
}
data += "\n";
}
StringBuilder str = new StringBuilder();
str.append(data);
Response.setHeader("Content-Disposition", "attachment; filename=\"" + dateToday + ".csv" + "\"");
Response.setCharacterEncoding("shift-jis");
Response.setContentType("text/plain;charset=shift-jis");
PrintWriter out = Response.getWriter();
out.write(str.toString());
out.flush();
out.close();
return true;
} 好人,谢谢
页:
[1]