package wsc.cn.microsoft;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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;
/**
* 读取excle文件的数据
* @author wsc
*
*/
public class ReadExles {
public static void main(String[] args) throws InvalidFormatException,
IOException {
// 读取文件
InputStream file = new FileInputStream("2012年08.12-09.08就业班课表.xls");
if (file != null) {
// 用workbookFactory工厂创建一个workbook
Workbook wb = WorkbookFactory.create(file);
// 循环取得文件中的第一个表
Sheet sheet = wb.getSheetAt(0);
String sheetname = sheet.getSheetName();
System.out.println("--------->>表名: " + sheetname + "<<---------");
int rowNum = sheet.getPhysicalNumberOfRows();
System.out.println("--------->>总行数: " + rowNum + "<<--------");
int rownum;
// 行和表格
Row row = null;
for (rownum = 0; rownum < sheet.getPhysicalNumberOfRows(); rownum++) {
row = sheet.getRow(rownum);
Cell cell1 = row.getCell(0);
// Date date = cell1.getDateCellValue();
// System.out.println(date);
Cell cell2 = row.getCell(1);
Cell cell3 = row.getCell(2);
Cell cell4 = row.getCell(3);
System.out.println(cell1 + "<---->" + cell2 + "<---->" + cell3
+ "<---->" + cell4);
}
}
}
}
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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;
/**
* 读取excle文件的数据
* @author wsc
*
*/
public class ReadExles {
public static void main(String[] args) throws InvalidFormatException,
IOException {
// 读取文件
InputStream file = new FileInputStream("2012年08.12-09.08就业班课表.xls");
if (file != null) {
// 用workbookFactory工厂创建一个workbook
Workbook wb = WorkbookFactory.create(file);
// 循环取得文件中的第一个表
Sheet sheet = wb.getSheetAt(0);
String sheetname = sheet.getSheetName();
System.out.println("--------->>表名: " + sheetname + "<<---------");
int rowNum = sheet.getPhysicalNumberOfRows();
System.out.println("--------->>总行数: " + rowNum + "<<--------");
int rownum;
// 行和表格
Row row = null;
for (rownum = 0; rownum < sheet.getPhysicalNumberOfRows(); rownum++) {
row = sheet.getRow(rownum);
Cell cell1 = row.getCell(0);
// Date date = cell1.getDateCellValue();
// System.out.println(date);
Cell cell2 = row.getCell(1);
Cell cell3 = row.getCell(2);
Cell cell4 = row.getCell(3);
System.out.println(cell1 + "<---->" + cell2 + "<---->" + cell3
+ "<---->" + cell4);
}
}
}
}