JAVA操作excel
2012-01-17 23:22
134 查看
package com.czp.xsl;
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();
}
}
}
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();
}
}
}
相关文章推荐
- java操作excel进行导入导出 jxl
- jxl.jar包简介/java操作excel (转)
- 将数据导出到Excel(java操作Excel)
- java操作excel——jxl和poi比较
- Java导出Excel文档使用poi操作
- java poi技术操作excel之写Excel(向Excel中写入值)
- 曹锋老师《Java操作 Excel 之 Poi 视频教程》学习笔记(1)
- Java操作Excel之Poi(三)
- java实现对Excel的读写操作
- java 调用 poi(apache的专门读写microsoft office API) 操作Excel
- JAVA-Excel文件操作
- Java使用jxl操作Excel
- java导入导出excel操作(jxl)
- java封装实现Excel建表读写操作
- Java操作Excel(读、写、搜索关键字、插入图片)
- apache POI3.2 java操作excel 设置数据有效性,实现excel单元格列表和提示
- java操作poi导出Excel
- Java操作Excel之JXL (填充EXCEL模板)
- java操作excel(HSSF样式)
- java对Excel操作