一 代码
package WorkbookTest;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
/**
* Copyright (C), 2020-2020, XXX有限公司
* FileName: Workbook
* Author: cakin
* Date: 2020/1/18
* Description: 获取对应Excel文件的Workbook对象
*/
public class WorkbookTest {
public static void main( String[] args ) {
String file = "F:\\Javatest\\tempTest\\test.xlsx";
File fileTest = new File(file);
Workbook workbook = getWorkbook(fileTest);
System.out.println("workbook:"+workbook);
}
public static Workbook getWorkbook( File file ) {
Workbook wb = null;
try {
if (file.exists() && file.isFile()) {
// 文件名
String fileName = file.getName();
// 文件扩展名
Stri