java 는 List 를 엑셀 로 내 보 냅 니 다.
package com.imageread;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class JavaArryList {
public static void main(String[] args) {
List workbookList=createlist();
//System.out.println(workbookList);
try {
writeToXls(workbookList);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static List createlist(){
List biaotou=new ArrayList();
List resultList=new ArrayList();
biaotou.add("name");
biaotou.add("id");
resultList.add(biaotou);
List neirong=new ArrayList();
neirong.add("A");
neirong.add("AA");
resultList.add(neirong);
neirong=new ArrayList();// ,
neirong.add("b");
neirong.add("bb");
resultList.add(neirong);
neirong=new ArrayList();
neirong.add("C");
neirong.add("CC");
resultList.add(neirong);
System.out.print(resultList);
return resultList;
}
public static void writeToXls(List resultList )throws Exception{
// EXCEL
Workbook wb = new HSSFWorkbook();
// SHEET
Sheet sheet1 = wb.createSheet(" 1");
if(resultList!=null){
for (int i = 0; i < resultList.size(); i++) {
//
Row row = sheet1.createRow(i);
List rowList=(List)resultList.get(i);
for (int j = 0; j < rowList.size(); j++) {
Cell cell = row.createCell(j);
String cellLiString=(String)rowList.get(j);
cell.setCellValue(cellLiString );
}
}
}
FileOutputStream fileOut = new FileOutputStream("d:\\testa.xls");
wb.write(fileOut);
fileOut.close();
}
}
첨부 파일 은 jar 에 의존 하 는 데 사 용 됩 니 다.