参照 :http://poi.apache.org/spreadsheet/quick-guide.html
package com.xiexh.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.examples.CreateCell;
public class NewWorkBook {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
readFile();
}
public static void createNewWorkBook1() throws Exception{
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
public static void createNewWorkBook2() throws Exception{
Workbook wxssb = new XSSFWorkbook();
FileOutputStream xsfOut = new FileOutputStream("workbook.xlsx");
wxssb.write(xsfOut);
xsfOut.close();
}
public static void createNewSheet() throws Exception{
Workbook wb = new HSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
FileOutputStream fileOut = new FileOutputStream("aaa.xls");
wb.write(fileOut);
fileOut.close();
}
public static void createNewSheet1() throws Exception{
Workbook wb = new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
FileOutputStream fileOut = new FileOutputStream("bbb.xlsx");
wb.write(fileOut);
fileOut.close();
}
public static void CreatNewCell()throws Exception{
Workbook wb = new HSSFWorkbook();
CreationHelper creationHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
for(int i = 0;i<20;i++){
Row row = sheet.createRow(i);
for(int j=0;j<5;j++){
Cell cell = row.createCell(j);
if(i!=0){
cell.setCellValue("wo ai ni:"+i+"X"+j);
}else{
cell.setCellValue("第"+j+"列");
}
}
}
FileOutputStream fileOut = new FileOutputStream("ccc.xls");
wb.write(fileOut);
fileOut.close();
}
public static void createDifferentofCells() throws Exception{
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
Row row = sheet.createRow((short)2);
row.createCell(0).setCellValue(1.1);
row.createCell(1).setCellValue(new Date());
row.createCell(2).setCellValue(Calendar.getInstance());
row.createCell(3).setCellValue("a string");
row.createCell(4).setCellValue(true);
row.createCell(5).setCellType(Cell.CELL_TYPE_ERROR);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("ddd.xls");
wb.write(fileOut);
fileOut.close();
}
public static void readFile()throws Exception{
Workbook wb = WorkbookFactory.create( new File("ccc.xls"));
Sheet sheet = wb.getSheetAt(0);
for(Row row : sheet){
for(Cell cell : row )
{
System.out.print(cell.getStringCellValue());
}
System.out.println();
}
}
}
相关推荐
poi apache-poi导入实例 导入excel 利用java的apache-poi读取每一行每一列,导入excel数据,两个for循环出来的[ ][ ] 承装数据
目前最新的apache-poi的jar包,对xls和xlsx两种格式都能支持。版本号:v3.12
Apache poi 操作 excel 文件压缩包,亲测可用
Apache POI是Apache软件基金会的开放源码函式库POI操作excel的JAR包!
Apache POI Excel操作 需要的文档,.介绍,相关jar包,maven中的配置等,比较全面
apache POI,文件读写 ,excel 对于使用apache poi 解析微软excel的一些文件
本人自己准备的poi 相关的word,excel的导入导出,做了详细的说明,内置两份ppt和poi jar包
NULL 博文链接:https://hanqunfeng.iteye.com/blog/2122817
apache poi 读取 Excel 的 jar 包 博文链接:https://wxinpeng.iteye.com/blog/231895
NULL 博文链接:https://zjkilly.iteye.com/blog/870334
org.apache.poi JAR包,解决import org.apache.poi.hssf.usermodel.HSSFWorkbook; 支持office全系excel文件解析。 import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; ...
附件是java poi 3.17的lib库及其依赖库,全部下载引用后,可以进行excel的读写操作,无需引用其他lib库。poi-3.17适用于jdk1.7。 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft ...
Apache POI是一个开源的Java读写Excel、WORD等微软OLE2组件文档的项目。目前POI已经有了Ruby版本。 结构: •HSSF - 提供读写Microsoft Excel XLS格式档案的功能。 •XSSF - 提供读写Microsoft Excel OOXML XLSX...
Apache Poi Excel导出 博文链接:https://zhiminsun.iteye.com/blog/1883347
POI使用excel模板循环输出行到文件并导出的一个小例子
Poi强大的操作技术方便了我们开发,Apache POI导入数据到Excel电子表格
Apache POI -3.7下载 POI3.7用于处理word.POI3.7用于处理word、excel、ppt等文档操作
版本:4.1.0 jar包个数:7个 apache的poi,操作Excel的包,亲测 jdk11 maven项目环境下包含本地jar使用有效,并给出了简单易用的封装。 传送门:我的博文:基于poi4.1.0的Excel表读写操作 日期:2020.12.15日
使用Apache POI的3.16版实现,Excel模板填充数据导出Excel报表
Apache POI导入和导出Excel文件