个性化阅读
专注于IT技术分析

apache poi读取单元内容

本文概述

Apache POI读取单元格内容示例

package poiexample;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class GettingCellContentExample {
	public static void main(String[] args) {
		try (InputStream inp = new FileInputStream("srcmini.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);
	    }
	}
}

这是我们要读取的电子表格文件。

执行完上面的示例后,它将从指定的单元格中读取值,并将以下输出输出到控制台。

输出:

Data: 200.0
赞(0)
未经允许不得转载:srcmini » apache poi读取单元内容

评论 抢沙发

评论前必须登录!