Jave将数据导出成ecxel表格
来源:互联网 发布:centos snmp 安装配置 编辑:程序博客网 时间:2024/05/17 23:22
下载jar包网址:
http://download.csdn.net/download/demon_ll/10040537
CreateUtil类:
public static void createExcelFile(String filename, XSSFWorkbook wb) { try { FileOutputStream fout = new FileOutputStream(filename); wb.write(fout); fout.close(); fout = null; } catch (Exception e) { e.printStackTrace(); } } public static void excelArticleFileWriter(String fileName, List<newsStat > clist) throws IOException { // 创建一个FileWriter对象 File file = new File(fileName); XSSFWorkbook wb = new XSSFWorkbook(); if (file.exists()) { InputStream instream = new FileInputStream(fileName); wb = new XSSFWorkbook(instream); } else { createExcelFile(fileName, wb); } XSSFSheet sheet = wb.getSheet("sheet0"); if (sheet == null) { sheet = wb.createSheet("sheet0"); } XSSFRow row = sheet.createRow((int) 0); int rowCount = sheet.getLastRowNum(); if (rowCount == 0) { row = sheet.createRow((int) 0); // HSSFCellStyle style = wb.createCellStyle(); Cell cell = row.createCell((short) 0); // HSSFCell cell = row.createCell((short) 0); cell.setCellValue("关键词"); cell = row.createCell((short) 1); cell.setCellValue("新闻"); cell = row.createCell((short) 2); } else { } for (int i = 0; i < clist.size(); i++) { ResultBean a = (ResultBean) clist.get(i); if (a != null) { // news; forum;blogs; press; row = sheet.createRow((int) rowCount + i + 1); row.createCell((short) 0).setCellValue(a.getKeyword()); row.createCell((short) 1).setCellValue(a.getNews()); } } try { FileOutputStream fout = new FileOutputStream(fileName); wb.write(fout); fout.close(); fout = null; System.exit(1); } catch (Exception e) { e.printStackTrace(); } }
Bean:
public class newsStat {
private String keyword;
private int news;
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public int getNews() {
return nwcounts;
}
public void setNews(int news) {
this.news= news;
}
}
main:
public static void main(String[] args) throws IOException { List<newsStat> list = new ArrayList(); for (int i = 0; i < 100; i++) { newsStat n = new newsStat(); n.setKeyword("test" + i); n.setNews(10); list.add(n); } excelArticleFileWriter("d:\\test.xlsx", list); }
ok,完成了
阅读全文
0 0
- Jave将数据导出成ecxel表格
- php 将mysql数据导出成表格形式
- 用php将数据库中数据导出成excel表格
- asp.net将数据导出Execl表格
- 将MongoDB中的数据导出为表格
- 将数据库数据导出至Excel表格
- 将JTable导出成xls表格
- javascript 将表格导出成Excel
- 将表格中的数据导出到EXCEL表中的
- 将数据库的数据导出到excel表格中。
- Java将数据导出到excel表格中
- 如何将数据库中数据导出Execl表格
- .net 将数据库中的数据导出到Excel表格中
- NetBeans 将表格 的数据导出到 excel
- mysql:day6--将数据导出到xls表格
- 将Excel表格中的数据导出到xml文件中
- wicket框架下如何将表格数据导出Excel
- php 将数据 以excel 表格的形式导出
- JS笔记
- mybatis的配置元素--typeHandler类型处理器
- MySQL redo与undo
- 简单的BaseActivity
- pooling mean max 前向和反向传播
- Jave将数据导出成ecxel表格
- viewpager
- Ubuntu14.04虚拟机和宿主机(win7)之间的文件传输 (VMwareTools)篇 网上
- eclipse快捷键
- C#遍历文件夹及文件
- 【慕课网_性能优化之MySQL优化_学习】【09】
- Alwayson 同步模式的坑
- 关于oracle+ibatis批量insert的写法
- ElasticSearch 5.0及head插件安装