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();
}
}