⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excelimportimpl.java

📁 这是一个用java三层框架做的ISS学员管理系统
💻 JAVA
字号:
package org.pontifex.commons.fileupload;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.pontifex.util.StringUtil;

public class ExcelImportImpl implements ExcelImport {
	
	private Excel workbook;
	
	private File file ;
	
	Map error ;
	
	public ExcelImportImpl(){
		
	}
	
	public ExcelImportImpl(File file){
		this.file = file ;
	}
	

	public boolean isExcelFile() throws ExcelException, IOException {
		if(file==null||!file.exists())
			throw new ExcelException("The file is Empty !");
		if(file.isDirectory())
			return false;
		String fileName = file.getName();
		if(StringUtil.isEmpty(fileName))
			throw new ExcelException("The file name is Empty !");
		String aa = fileName.substring(fileName.lastIndexOf("."));
		if(aa.equals(".xls"))return true;
		return false;
	}
	
	private boolean isExcelFile(File file) throws ExcelException, IOException{
		if(read(file))
			return isExcelFile();
		return false;
	}

	public boolean read(File inputfile) throws IOException {
		if(inputfile==null||!inputfile.exists())
			return false;
		file = inputfile ;
		return true;
	}
	
	public Excel processExcel() throws ExcelException, IOException{
		return processExcel(file);
	}
	
	private Excel processExcel(File file) throws ExcelException, IOException{
		if(!isExcelFile(file))return null;
		InputStream inputStream = null ;
		try{
			inputStream = new FileInputStream(file);	
	        workbook = new Excel(inputStream);
	        error = new HashMap();
	        validate();
	        return workbook;
		}finally{
			if(inputStream!=null)inputStream.close();
		}
	}
	
	private void validate() {
		
	}

	public static void main(String[] args) throws IOException{
		ExcelImport excelImport = new ExcelImportImpl();
		excelImport.read(new File("e:\\新建 Microsoft Excel 工作表.xls"));
		System.out.println(excelImport.isExcelFile());
		Excel excel= excelImport.processExcel();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -