您的位置:首页 > 其它

poi Excel写数据

2016-03-03 16:47 204 查看
public static void writeExcel(List<String[]> list,String[] format,String fileName){
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
//获取第一行
HSSFRow row = sheet.createRow(0);
//第一行为的标题
for(int i = 0 ; i < format.length ; i++){
row.createCell(i).setCellValue(format[i]);
}
//将list中的数据添加到Excel中
for(int j = 0 ; j < list.size() ; j++ ){
HSSFRow row2 = sheet.createRow(j+1);
String[] temp = list.get(j);
for(int k = 0 ; k < temp.length ; k++){
row2.createCell(k).setCellValue(temp[k]);
}
}
try {
//保存到指定的文件中
FileOutputStream outStream = new FileOutputStream(fileName);
workbook.write(outStream);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: