Java读取EXCEL表格数据,文件为.xlsx格式,并且可以判断数据为什么类型

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Map;


import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;

/** 
* @author FUCCKL
* @version  2019.1.7 14:30~
*    读取EXCEL数据存放到列表里,可以判断数据属于什么类型
*/
public class readdata {

	static int row=0;
	static int column=0;
	public 	static ArrayList readdata(String path)throws Exception//读取字符串数据
	{
		XSSFWorkbook workbook;
		XSSFSheet sheet;
		XSSFCell cell;
		
		ArrayList xlist=new ArrayList();
		InputStream iStream=new FileInputStream(path);
		 workbook=new XSSFWorkbook(iStream); 

	 sheet=workbook.getSheetAt(0);
	 row=sheet.getLastRowNum()+1;//获取行数
     column=sheet.getRow(0).getPhysicalNumberOfCells();//获取列数

 	for(int i=0;i

读取的数据被存放到自己定义的列表里,调用方式如下:

ArrayList movielist=new ArrayList();
String path0="D:\\eclipse-workspace\\recommend system\\movielist.xlsx";
movielist=readdata.readdata(path0);

 

你可能感兴趣的:(JAVA)