package jwsample;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Sample1 {
public static void main(String[] args) {
try {
(new Sample1()).go();
} catch (Exception ex) {
System.err.println(ex);
}
}
/**
* 生成简单的Sheet
*/
void go() throws Exception {
//生成Excel文件的Workbook对象 (1)
HSSFWorkbook wb = new HSSFWorkbook();
// 生成「sheet1」Sheet对象 (2)
HSSFSheet sheet1 = wb.createSheet("sheet1");
// 生成行 (3)
HSSFRow row0 = sheet1.createRow(0);
// 生成列
row0.createCell((short)0).setCellValue("CellData"); (4)
row0.createCell((short)1).setCellValue(123);
// 把WorkBook对象打印到Excel文档
FileOutputStream fileOut = new FileOutputStream("sample1.xls"); (5)
wb.write(fileOut);
fileOut.close();
}
}