import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ReadXSL {
public static void main(String[] args) throws Exception {
InputStream myxls = new FileInputStream("D:/开发软件/PMTool/PMTool/NeInterface/ENODEB/eBBU530V100R001C00IDC00/性能接口文档.xls");
HSSFWorkbook wb = new HSSFWorkbook(myxls);
HSSFSheet sheet = wb.getSheetAt(0); // 第一个工作表
int rows = sheet.getLastRowNum();
for(int i=0;i<rows;i++)
{
HSSFRow row = sheet.getRow(i);
int rs = row.getLastCellNum();
for(int j=0;j<rs;j++)
{
HSSFCell cell = row.getCell((short)j);
if(cell!=null)
{
System.out.println(cell.getCellType());
// if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
// System.out.print(cell.getStringCellValue()+"\t");
// } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
// {
// System.out.print(cell.getNumericCellValue()+"\t");
// }else {
// System.out.print(cell.getCellNum()+"\t");
// }
}
}
System.out.println();
}
}
}
===========================
package com.czp;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import org.apache.poi.hssf.usermodel.HSSFCell;
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.ss.usermodel.WorkbookFactory;
public class XLSReader {
public static void main(String[] args) throws Exception {
InputStream myxls = new FileInputStream("F:/123.xls");
Workbook wb = WorkbookFactory.create(myxls);
Sheet sheet = wb.getSheetAt(0); // 第一个工作表
int rows = sheet.getPhysicalNumberOfRows();
for (int i = sheet.getFirstRowNum(); i < rows; i++) {
Row row = sheet.getRow(i);
int rs = row.getPhysicalNumberOfCells();
for (int j = 0; j < rs; j++) {
Cell cell = row.getCell(j);
if (cell != null) {
System.out.println(cell.getRichStringCellValue());
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
System.out.print(cell.getStringCellValue() + "\t");
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.print(BigDecimal.valueOf(cell
.getNumericCellValue()) + "\t");
} else {
System.out.print(cell.getRichStringCellValue() + "\t");
}
}
}
System.out.println();
}
}
}