Apache POI Excel 读取单元格内容
Apache POI 读取单元格内容示例
以下为我们需要读取的Excel文件和内容
通过以下代码读取其内容:
package com.yiidian;
import org.apache.poi.ss.usermodel.*;
import java.io.FileInputStream;
import java.io.InputStream;
public class GettingCellContentExample {
public static void main(String[] args) {
try (InputStream inp = new FileInputStream("yiidian.xls")) {
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell != null)
System.out.println("Data: "+cell);
else
System.out.println("Cell is empty");
}catch(Exception e) {
System.out.println(e);
}
}
}
输出结果为:
热门文章
优秀文章