fcui 发表于 2008-1-11 10:50:41

Dataset如何写成csv文件

想请教一下,如何将RFT中连接数据库获得的Dataset写成csv文件

lovetest6 发表于 2008-1-11 17:47:11

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;
}

wonew1228 发表于 2008-5-20 11:06:08

好人,谢谢
页: [1]
查看完整版本: Dataset如何写成csv文件