winform导出csv

a124819202 2010-01-28 02:25:44
winform怎么将Listview中的数据压缩导出为csv文件!
...全文
396 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
a124819202 2010-01-28
  • 打赏
  • 举报
回复
可是怎么压缩?
Jason-Jin 2010-01-28
  • 打赏
  • 举报
回复
用streamwrite就行,csv说白了就是逗号分割的文档,数据读入到六种,读取字段然后自己加入逗号,
StreamWriter sw = System.IO.File.AppendText("11 + ".csv");
就可以了
zhang_huatao 2010-01-28
  • 打赏
  • 举报
回复
这是JAVA版 导出CSV的一段程序,可参考一下
zhang_huatao 2010-01-28
  • 打赏
  • 举报
回复
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.hansky.intf.butterfly.IButterflyContext;

sourceRelative("common.bsh");

static String csvTempDirName = "csv-temp";
HttpSession hs = request.getSession();
String csvDir = "/session_static/" + hs.getId() + "/" + csvTempDirName;
String url = "/butterfly/" + csvDir + "/";

void httpForward(HttpServletRequest req, HttpServletResponse res, String path) {
RequestDispatcher rd = request.getRequestDispatcher(path);
rd.forward(request, response);
}

// 把临时文件放在 /products/rsrc/chtml/csv-temp
File getTempCsvDir(IButterflyContext ctx) {

File rootDir = new File(ctx.getRootDir(), "chtml" + csvDir);
rootDir.mkdirs();
return rootDir;
}

public void createCvs(){
IButterflyContext ctx = (IButterflyContext)request.getAttribute("hs.butterfly.context");
List reportList = new ArrayList();

StringBuffer sb = new StringBuffer();
sb = getDataList(ctx, reportList);

// 写入文件
File f = null;
FileOutputStream fos = null;

// 文件名为当前时间,可以根据需要进行修改
String fileName = System.currentTimeMillis() + ".csv";
url = url + fileName;

try {
f = new File(getTempCsvDir(ctx), fileName);
fos = new FileOutputStream(f);
fos.write(sb.toString().getBytes("gbk"));

} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (fos != null) {
fos.close();
}
}
}

// 设置MIME type,并设置URL
createCvs();
response.setContentType("application/ms-excel");
response.sendRedirect(url);
dream_ll 2010-01-28
  • 打赏
  • 举报
回复
读取listview里面的内容,用streamwriter写入到csv文件

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧