poi写入读取excel 2007版xlsx 97版xls
来源:互联网 发布:织梦cms整站源码下载 编辑:程序博客网 时间:2024/05/05 23:24
poi写入读取excel 2007版xlsx 97版xls
package cn.com.cloud.sea.office.test;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class TestReadAndWrite {public static void main(String[] args) throws IOException {String path = "d:/";String fileName = "test";String fileType = "xlsx";writer(path, fileName, fileType);read(path, fileName, fileType);}private static void writer(String path, String fileName,String fileType) throws IOException {//创建工作文档对象Workbook wb = null;if (fileType.equals("xls")) {wb = new HSSFWorkbook();}else if(fileType.equals("xlsx")){wb = new XSSFWorkbook();}else{System.out.println("您的文档格式不正确!");}//创建sheet对象Sheet sheet1 = (Sheet) wb.createSheet("sheet1");//循环写入行数据for (int i = 0; i < 5; i++) {Row row = (Row) sheet1.createRow(i);//循环写入列数据for (int j = 0; j < 8; j++) {Cell cell = row.createCell(j);cell.setCellValue("测试"+j);}}//创建文件流OutputStream stream = new FileOutputStream(path+fileName+"."+fileType);//写入数据wb.write(stream);//关闭文件流stream.close();}public static void read(String path,String fileName,String fileType) throws IOException{InputStream stream = new FileInputStream(path+fileName+"."+fileType);Workbook wb = null;if (fileType.equals("xls")) {wb = new HSSFWorkbook(stream);}else if (fileType.equals("xlsx")) {wb = new XSSFWorkbook(stream);}else {System.out.println("您输入的excel格式不正确");}Sheet sheet1 = wb.getSheetAt(0);for (Row row : sheet1) {for (Cell cell : row) {System.out.print(cell.getStringCellValue()+" ");}System.out.println();}}}
- poi写入读取excel 2007版xlsx 97版xls
- poi写入读取excel 2007版xlsx 97版xls
- POI读取EXCEL下xlsx,xls文件
- poi读取excel(xls,xlsx)
- java读取与写入excel(.xls .xlsx)
- POI读取XLS、XLSX
- POI读取加密的EXCEL(兼容XLS,XLSX格式)
- JavaEE POI读取 Excel中的数据,(Excel2003(xls), Excel2007(xlsx))
- java的poi技术读取Excel[xls,xlsx]
- java:poi读取excel文件,分xls和xlsx
- java使用POI读取excel文件,兼容xls和xlsx
- POI读取xls和xlsx
- POI读取xls和xlsx
- POI读取xls、xlsx(个人认为用JXL效果更好,但是JXL并不支持07版的Excel)
- Java中通过POI读取Excel 2003 - 2007的xls,xlsx格式
- 用poi解析excel,支持office2003、2007(xls,xlsx)
- poi 解析 Excel(xls xlsx)
- POI解析Excel(.xls)和Excel2007(.xlsx)
- ORACLE 索引概述
- android应用开发笔记---SQLite使用
- MFC工程环境下,制作Activex ocx取消IE浏览器的安全提示
- 关于狂人C第九章练习题二
- ini文件解析中的STL
- poi写入读取excel 2007版xlsx 97版xls
- 7种常用排序算法总结:
- 函数的调用----特殊的数
- 寂寞林
- Kahan's Summation Formula原理—它是如何避免大数吃小数的
- va_list
- 小菜编程成长日志--代码无错就是好?
- 基于S3C2440的Linux内核移植和yaffs2文件系统制作--启动系统
- 分页的存储过程