环境:eclipse
方法:使用jxl.jar包
步骤一:
打开eclipse,创建Maven项目,在pom.xml中添加jxl依赖
pom.xml
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
<scope>${scope}</scope>
</dependency>
步骤二:
创建ExcelUtil类:
package Tool;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Cell;
import jxl.JXLException;
import jxl.Sheet;
import jxl.Workbook;
public class ExcelUtil {
private static Cell cel;
//获取给定单元格的内容
public static String getcell(String filename,int sheet,int row ,int column) throws JXLException, IOException{
FileInputStream filein=new FileInputStream(filename);
Workbook wb=Workbook.getWorkbook(filein);
Sheet sh=wb.getSheet(sheet);
cel=sh.getCell(row,column);
return cel.getContents();
}
}
网友评论