mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
commit
98e46d7634
@ -50,6 +50,16 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
|||||||
this(FileUtil.file(excelFilePath), sheetIndex);
|
this(FileUtil.file(excelFilePath), sheetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param excelFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
|
* @param sheetName sheet名,第一个默认是sheet1
|
||||||
|
*/
|
||||||
|
public ExcelReader(String excelFilePath, String sheetName) {
|
||||||
|
this(FileUtil.file(excelFilePath), sheetName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造(读写方式读取)
|
* 构造(读写方式读取)
|
||||||
*
|
*
|
||||||
|
@ -154,6 +154,22 @@ public class ExcelUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Excel读取器,通过调用{@link ExcelReader}的read或readXXX方法读取Excel内容
|
||||||
|
*
|
||||||
|
* @param bookFilePath Excel文件路径,绝对路径或相对于ClassPath路径
|
||||||
|
* @param sheetName sheet名,第一个默认是sheet1
|
||||||
|
* @return {@link ExcelReader}
|
||||||
|
* @since 3.1.1
|
||||||
|
*/
|
||||||
|
public static ExcelReader getReader(String bookFilePath, String sheetName) {
|
||||||
|
try {
|
||||||
|
return new ExcelReader(bookFilePath, sheetName);
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Excel读取器,通过调用{@link ExcelReader}的read或readXXX方法读取Excel内容
|
* 获取Excel读取器,通过调用{@link ExcelReader}的read或readXXX方法读取Excel内容
|
||||||
*
|
*
|
||||||
|
@ -4,6 +4,9 @@ import cn.hutool.poi.excel.cell.CellLocation;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ExcelUtilTest {
|
public class ExcelUtilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,4 +53,12 @@ public class ExcelUtilTest {
|
|||||||
writer.writeCellValue(1, 2, "设置值");
|
writer.writeCellValue(1, 2, "设置值");
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getReaderByBookFilePathAndSheetNameTest() {
|
||||||
|
ExcelReader reader = ExcelUtil.getReader("aaa.xlsx", "12");
|
||||||
|
List<Map<String, Object>> list = reader.readAll();
|
||||||
|
reader.close();
|
||||||
|
Assert.assertEquals(1L, list.get(1).get("鞋码"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user