---
title: "把数据导入到.CSV文件,用的是opencsv-1.8.jar框架"
author: "roses"
date: "2011-03-16T15:05:46Z"
tags: ["C", "C#", "C++", "J#", "框架"]
categories: ["编程语言"]
slug: "csv-opencsv-1-8-jar"
draft: false
lastmod: "2011-03-16T15:05:46Z"
id: 964230
url: "https://roses.iteye.com/blog/964230"
---

public static void main(String\[] args) { try { CSVWriter c = new CSVWriter(new FileWriter("d://cc.csv")); //报表名称 String \[] title = {"以下是摘要，表头与内容信息"}; c.writeNext(title); //得到摘要信息 List sum = summary(); String \[]ss = new String\[sum.size()]; for(int i =0;i map = head(); String \[]sm = new String\[map.size()]; for(int i =0;i&gt; data = initRowdata(); for(int i = 0; i&lt; data.size();i++){ Map li = data.get(i); //得到每一行 String \[] tmp = new String\[li.size()]; for(int j =0;j&gt; initRowdata(){ List&gt; list = new ArrayList&gt;(); Map map = new HashMap(); map.put("0", "one"); map.put("1", "two"); map.put("2", "three"); map.put("3", "four"); map.put("4", "five"); map.put("5", "six"); list.add(0, map); Map map2 = new HashMap(); map2.put("0", "jack"); map2.put("1", "rose"); map2.put("2", "judy"); map2.put("3", "vivi"); map2.put("4", "vick"); map2.put("5", "angel"); list.add(1, map2); return list; } private static List summary(){ List list = new ArrayList(); String a = "时间：2011-3-16"; String b = "条数：156"; String c = "MOLEVEL：BSC"; String d = "TIMELEVEL:DAILY"; String e = "用户：jack"; list.add(0, a); list.add(1, b); list.add(2, c); list.add(3, d); list.add(4, e); return list; } private static Map head(){ Map map = new HashMap(); map.put("0", "name"); map.put("1", "sex"); map.put("2", "heiht"); map.put("3", "width"); map.put("4", "tele"); map.put("5", "hobi"); return map; }