之前POI 4.x版本踩了不少坑,痛定思痛直接上5.x版本,看看新坑会不会能填掉4.x问题的空缺
一、环境搭建
依赖库引用
dependencies {
implementation 'org.apache.poi:poi:5.2.0'
implementation 'org.apache.poi:poi-ooxml:5.2.0'
// Android底层库是不支持poi框架解析xlsx文件的, 因为XMLStreamReader仅在JAVASE中提供.需要引入javax的组件包解决此问题
implementation 'stax:stax-api:1.0.1'
}
二、代码示例
public List<String> readExcel(InputStream ins) {
List<String> strings = new ArrayList<>();
try {
Workbook workbook = WorkbookFactory.create(ins);
Sheet sheet = workbook.getSheetAt(0);
for (Row row: sheet) {
for (Cell cell: row) {
if (cell.getCellType() == CellType.NUMERIC) {
Log.i(TAG, "readExcel: data = " + cell.getNumericCellValue());
} else if (cell.getCellType() == CellType.STRING) {
Log.i(TAG, "