如何使用Java POI生成Excel表文件 !
2013-12-05 14:49
274 查看
// 使用Java POI
// 把要两个JAR文件放到lib/ext下
// code run against the jakarta-poi-1.5.0-FINAL-20020506.jar.
// and commons-logging-1.0.jar
例子程序:
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
// code run against the jakarta-poi-1.5.0-FINAL-20020506.jar.
// and commons-logging-1.0.jar
public class PoiTest {
static public void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("d://foo.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
wb.setSheetName(0, "Matrix");
for(short i=0; i<50; i++) {
HSSFRow row = s.createRow(i);
for(short j=0; j<50; j++) {
HSSFCell cell = row.createCell(j);
cell.setCellValue(""+i+","+j);
}
}
wb.write(fos);
fos.close();
}
}
// 把要两个JAR文件放到lib/ext下
// code run against the jakarta-poi-1.5.0-FINAL-20020506.jar.
// and commons-logging-1.0.jar
例子程序:
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
// code run against the jakarta-poi-1.5.0-FINAL-20020506.jar.
// and commons-logging-1.0.jar
public class PoiTest {
static public void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("d://foo.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
wb.setSheetName(0, "Matrix");
for(short i=0; i<50; i++) {
HSSFRow row = s.createRow(i);
for(short j=0; j<50; j++) {
HSSFCell cell = row.createCell(j);
cell.setCellValue(""+i+","+j);
}
}
wb.write(fos);
fos.close();
}
}
相关文章推荐
- Java中对象序列化的作用是什么
- Myeclipse优化
- Eclipse中添加文档注释快捷键
- Java第九章作业
- java环境变量设置
- Java Design Pattern for Concurrent Multiple
- Java多线程设计模式(6)两阶段终止模式
- JNDI中 java:comp/env 是什么意思?
- mybatis与spring整合(基于配置文件)
- JAVA中的Set集合类
- struts2-ajax-传递map集合
- 什么是java future模式
- java循环map
- 从几个sample来学习Java堆,方法区,Java栈和本地方法栈
- Struts2中实现随机验证码
- Java Heap sapce 与 Java PermGen space
- Java内存溢出的详细解决方案
- Eclipse中修改包名或类名
- 最常用的Java库一览
- struts2-ajax-传递list集合