https://blog.csdn.net/Imain/article/details/1111194
excel包依赖:https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl/2.6.12
https://www.cnblogs.com/linjiqin/p/3540266.html
package com.zgx.excel; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import org.testng.annotations.Test; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; /** * @author * @version 1.0 * @time 2019/5/24 16:35 */ public class Excel { /*** * 需求: * 1、根据某个单元格的内容定位出此单元格的位置 * 2、 */ InputStream inputStream; Workbook rwb; public void base() { /*** * 读取表,并创建workbook对象 * 备注:需要讲表格另存为xls格式才会读取成功,不能只改后缀名 */ { try { inputStream = new FileInputStream("表路径"); try { rwb = Workbook.getWorkbook(inputStream); } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } } } @Test public void ttt() { base(); /*** *对表进行操作 */ //获取第一张sheet表 Sheet sheet1 = rwb.getSheet(0); //获取某个单元格的值 Cell cell1 = sheet1.getCell(0, 0); String cell1string = cell1.getContents().toString(); //根据内容查找单元格的位置 Cell cell2 = sheet1.findCell("T_G2_05"); String cell2string = cell2.getContents().toString(); int row = cell2.getRow(); int column = cell2.getColumn(); System.out.println("T_G2_05:" + row + "行," + column + "列。 内容:" + cell2string); //验证 System.out.println("值:" + cell1string); } }