45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:使用Java POI生成Excel表文件的方法

使用Java POI生成Excel表文件的方法

2016-09-05 08:02:09 来源:www.45fan.com 【

使用Java POI生成Excel表文件的方法

// 使用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();

}

}

 

本文地址:http://www.45fan.com/a/question/72546.html
Tags: 生成 POI Java
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部