首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

java导出Excel事例(poi)

2013-02-24 
java导出Excel例子(poi)源:wenku.baidu.com/view/43e7676825c52cc58bd6be99.html评:public class creatFil

java导出Excel例子(poi)

源:wenku.baidu.com/view/43e7676825c52cc58bd6be99.html

评:

public class creatFile {
??? static public void main(String[] args) throws Exception {

??? ??? FileOutputStream fos = new FileOutputStream("d:\\creatFile.xls");
??? ??? HSSFWorkbook wb = new HSSFWorkbook();
??? ??? HSSFSheet s = wb.createSheet();
??? ??? wb.setSheetName(0, "first sheet");
??? ??? HSSFRow row = s.createRow(0);
??? ??? HSSFCell cell = row.createCell((short)0);
??? ??? cell.setCellValue("Hello! This message is generated from POI.");
??? ??? wb.write(fos);
??? ??? fos.close();
??? }
}

?

?

public class AppendFile {

??? public static void main(String[] args) throws FileNotFoundException, IOException
??? {??? ???
??? ??? POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream("d:\\test.xls"));???
??? ?
??? ??? //? 创建一个新的Excel
??? ??? HSSFWorkbook wb = new HSSFWorkbook(fs);
??? ???
??? ??? //? 在所创建的Excel中新建一个sheet页
??? ??? HSSFSheet sheet = wb.getSheetAt(0);
??? ???
??? ??? //? 取该sheet页的第13行
??? ??? HSSFRow row = sheet.getRow(12);
??? ???
??? ??? //? 第8列的单元格
??? ??? HSSFCell cell = row.getCell((short)7);

??? ??? System.out.println(cell);
??? ??? String??? src??? = "单元格";
??? ???
??? ??? //? 在所取得单元格中书写内容
??? ??? cell.setEncoding(HSSFCell.ENCODING_UTF_16);
??? ??? cell.setCellValue(src);
??? ???
??? ?
??? ??? // Write the output to a file
??? ??? FileOutputStream fileOut = new FileOutputStream("d:\\ww.xls");
??? ???
??? ??? wb.write(fileOut);
??? ???
??? ??? fileOut.close();
??? }
}

热点排行