exceljavapoi
Ⅰ java操作Excel要用的poi包怎么下
打开那个页面后
你会看到
Apache Download Mirrors
We suggest the following mirror site for your download:
http://www.devlib.org/apache/jakarta/poi/
Other mirror sites are suggested below. Please use the backup mirrors only to download PGP and MD5 signatures to verify your downloads or if no other mirrors are working.
点击http://www.devlib.org/apache/jakarta/poi/
打开后会看到3个连接
Parent Directory
dev
release
选择release里的bin连接,应该就有你想要的东西了吧
Ⅱ 使用java读取xlsx格式的execl,除了poi还有哪些方式
一般就用POI、JXL
但是JXL2011年后好像就没更新了,不支持Office2007后的xlsx文件
所以大多数都在用POI
两者使用大同小异,都一样简单,找个Demo就能熟悉
若因限制不能使用POI(平台冲突等)是否需要考虑回头用JXL?那要看你能否接受只支持office2007的 xls文件
Ⅲ java excel poi 怎么导入
1、下载poi相关jar,maven的集成如下:(把${poi.version}替换成你要的版本)
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>
2、根据poi相关api读取sheet、row、cell,获得excel的数据:
封装row的对象,即每一行数据为一个对象,每个cell为对象里的一个属性,
整个sheet的数据装进集合里;
3、处理数据,可以对数据进行验证或其他操作;
4、写数据库操作。
Ⅳ 如何使用Java POI生成Excel表文件
()throwsIOException{
Stringpath="C:\poi2.xlsx";
XSSFWorkbookworkbook=newXSSFWorkbook();
XSSFSheetsheet=workbook.createSheet("我的");
XSSFRowrow=sheet.createRow(0);
XSSFCellcell=row.createCell(0);
cell.setCellValue("我是POI写入的");
XSSFRowrow1=sheet.createRow(1);
XSSFCellcell1=row1.createCell(0);
cell1.setCellValue("2010");
FileOutputStreamoutputStream=newFileOutputStream(path);
workbook.write(outputStream);
outputStream.close();
}
()throwsIOException{
Stringpath="C:\poi2.xls";
HSSFWorkbookworkbook=newHSSFWorkbook();
HSSFSheetsheet=workbook.createSheet("我的Excel");
HSSFRowrow=sheet.createRow(0);
HSSFCellcell=row.createCell(0);
cell.setCellValue("我是POI写入的");
FileOutputStreamoutputStream=newFileOutputStream(path);
workbook.write(outputStream);
outputStream.close();
}
Ⅳ java poi 需要装excel吗
不装office软件,也可以操作poi
Ⅵ java poi怎么获取excel单元格的内容
packagee.sjtu.erplab.poi;
importjava.io.InputStream&ch=ww.xqy.chain"target="_blank"class="link-ke">FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;
importjava.io.InputStream;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importjava.util.HashMap;
importjava.util.Map;
importorg.apache.poi.hssf.usermodel.HSSFCell;
importorg.apache.poi.hssf.usermodel.HSSFDateUtil;
importorg.apache.poi.hssf.usermodel.HSSFRow;
importorg.apache.poi.hssf.usermodel.HSSFSheet;
importorg.apache.poi.hssf.usermodel.HSSFWorkbook;
importorg.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
*操作Excel表格的功能类
*/
publicclassExcelReader{
privatePOIFSFileSystemfs;
privateHSSFWorkbookwb;
privateHSSFSheetsheet;
privateHSSFRowrow;
/**
*读取Excel表格表头的内容
*@paramInputStream
*@returnString表头内容的数组
*/
publicString[]readExcelTitle(InputStreamis){
try{
fs=newPOIFSFileSystem(is);
wb=newHSSFWorkbook(fs);
}catch(IOExceptione){
e.printStackTrace();
}
sheet=wb.getSheetAt(0);
row=sheet.getRow(0);
//标题总列数
intcolNum=row.getPhysicalNumberOfCells();
System.out.println("colNum:"+colNum);
String[]title=newString[colNum];
for(inti=0;i<colNum;i++){
//title[i]=getStringCellValue(row.getCell((short)i));
title[i]=getCellFormatValue(row.getCell((short)i));
}
returntitle;
}
/**
*读取Excel数据内容
*@paramInputStream
*@returnMap包含单元格数据内容的Map对象
*/
publicMap<Integer,String>readExcelContent(InputStreamis){
Map<Integer,String>content=newHashMap<Integer,String>();
Stringstr="";
try{
fs=newPOIFSFileSystem(is);
wb=newHSSFWorkbook(fs);
}catch(IOExceptione){
e.printStackTrace();
}
sheet=wb.getSheetAt(0);
//得到总行数
introwNum=sheet.getLastRowNum();
row=sheet.getRow(0);
intcolNum=row.getPhysicalNumberOfCells();
//正文内容应该从第二行开始,第一行为表头的标题
for(inti=1;i<=rowNum;i++){
row=sheet.getRow(i);
intj=0;
while(j<colNum){
//每个单元格的数据内容用"-"分割开,以后需要时用String类的replace()方法还原数据
//也可以将每个单元格的数据设置到一个javabean的属性中,此时需要新建一个javabean
//str+=getStringCellValue(row.getCell((short)j)).trim()+
//"-";
str+=getCellFormatValue(row.getCell((short)j)).trim()+"";
j++;
}
content.put(i,str);
str="";
}
returncontent;
}
/**
*获取单元格数据内容为字符串类型的数据
*
*@paramcellExcel单元格
*@returnString单元格数据内容
*/
(HSSFCellcell){
StringstrCell="";
switch(cell.getCellType()){
caseHSSFCell.CELL_TYPE_STRING:
strCell=cell.getStringCellValue();
break;
caseHSSFCell.CELL_TYPE_NUMERIC:
strCell=String.valueOf(cell.getNumericCellValue());
break;
caseHSSFCell.CELL_TYPE_BOOLEAN:
strCell=String.valueOf(cell.getBooleanCellValue());
break;
caseHSSFCell.CELL_TYPE_BLANK:
strCell="";
break;
default:
strCell="";
break;
}
if(strCell.equals("")||strCell==null){
return"";
}
if(cell==null){
return"";
}
returnstrCell;
}
/**
*获取单元格数据内容为日期类型的数据
*
*@paramcell
*Excel单元格
*@returnString单元格数据内容
*/
privateStringgetDateCellValue(HSSFCellcell){
Stringresult="";
try{
intcellType=cell.getCellType();
if(cellType==HSSFCell.CELL_TYPE_NUMERIC){
Datedate=cell.getDateCellValue();
result=(date.getYear()+1900)+"-"+(date.getMonth()+1)
+"-"+date.getDate();
}elseif(cellType==HSSFCell.CELL_TYPE_STRING){
Stringdate=getStringCellValue(cell);
result=date.replaceAll("[年月]","-").replace("日","").trim();
}elseif(cellType==HSSFCell.CELL_TYPE_BLANK){
result="";
}
}catch(Exceptione){
System.out.println("日期格式不正确!");
e.printStackTrace();
}
returnresult;
}
/**
*根据HSSFCell类型设置数据
*@paramcell
*@return
*/
(HSSFCellcell){
Stringcellvalue="";
if(cell!=null){
//判断当前Cell的Type
switch(cell.getCellType()){
//如果当前Cell的Type为NUMERIC
caseHSSFCell.CELL_TYPE_NUMERIC:
caseHSSFCell.CELL_TYPE_FORMULA:{
//判断当前的cell是否为Date
if(HSSFDateUtil.isCellDateFormatted(cell)){
//如果是Date类型则,转化为Data格式
//方法1:这样子的data格式是带时分秒的:2011-10-120:00:00
//cellvalue=cell.getDateCellValue().toLocaleString();
//方法2:这样子的data格式是不带带时分秒的:2011-10-12
Datedate=cell.getDateCellValue();
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");
cellvalue=sdf.format(date);
}
//如果是纯数字
else{
//取得当前Cell的数值
cellvalue=String.valueOf(cell.getNumericCellValue());
}
break;
}
//如果当前Cell的Type为STRIN
caseHSSFCell.CELL_TYPE_STRING:
//取得当前的Cell字符串
cellvalue=cell.getRichStringCellValue().getString();
break;
//默认的Cell值
default:
cellvalue="";
}
}else{
cellvalue="";
}
returncellvalue;
}
publicstaticvoidmain(String[]args){
try{
//对读取Excel表格标题测试
InputStreamis=newFileInputStream("d:\test2.xls");
ExcelReaderexcelReader=newExcelReader();
String[]title=excelReader.readExcelTitle(is);
System.out.println("获得Excel表格的标题:");
for(Strings:title){
System.out.print(s+"");
}
//对读取Excel表格内容测试
InputStreamis2=newFileInputStream("d:\test2.xls");
Map<Integer,String>map=excelReader.readExcelContent(is2);
System.out.println("获得Excel表格的内容:");
for(inti=1;i<=map.size();i++){
System.out.println(map.get(i));
}
}catch(FileNotFoundExceptione){
System.out.println("未找到指定路径的文件!");
e.printStackTrace();
}
}
}
Ⅶ java中poi怎么生成excel
网上好多啊 我给你找了一个例子 view plain to clipboardprint?
public static void main(String[] args) {
try {
String filepath = "d:\\问题清单.xls";
FileInputStream fis = new FileInputStream(filepath);
// POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream("d:\\OA问题清单.xls"));
// HSSFWorkbook hwb = new HSSFWorkbook(pfs);
HSSFWorkbook hwb = new HSSFWorkbook(fis);
// HSSFSheet hws = hwb.getSheetAt(0);
HSSFSheet hws = hwb.getSheet("问题清单");
HSSFRow row = hws.getRow(2);
HSSFCell cell = null;
cell = row.getCell((short) 1);
System.out.println("cellnumber:"+cell.getCellNum());
System.out.println("cellvalue:"+getExcelCellValue(cell));
cell.setCellValue(new Date());
cell = row.getCell((short)2);
HSSFRichTextString rts = new HSSFRichTextString("输入");
cell.setCellValue(rts);
FileOutputStream fos = new FileOutputStream(filepath);
hwb.write(fos);
fis.close();
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(poi.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(poi.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static String getExcelCellValue(HSSFCell cell) {
String ret = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DecimalFormat df = new DecimalFormat("#");
int celltype = cell.getCellType();
switch(celltype){
case HSSFCell.CELL_TYPE_NUMERIC:
if(HSSFDateUtil.isCellDateFormatted(cell)){
ret = sdf.format(cell.getDateCellValue());
}else{
ret = df.format(cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
ret = cell.getRichStringCellValue().toString();
break;
default:
}
return ret;
}
Ⅷ java中使用POI如何获得EXCEL中的一行数据
static public void main(String[] args){
try {
FileInputStream fis = new FileInputStream("d:\\aa.xls");
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet s = wb.getSheet("Sheet1");
HSSFRow row=s.getRow(0);
HSSFCell cell=row.getCell((short) 0);
System.out.println(cell.getStringCellValue());
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}