
用java提取上面的表格数据怎么获取。谢谢了,有什么帮助吗 ,希望能给与解答
使用EasyExcel正常读取就行,
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
</dependency>
Java实体类定义如下
import com.alibaba.excel.annotation.ExcelProperty;
public class CableData {
@ExcelProperty("物料描述")
private String materialDescription;
@ExcelProperty("物料编码")
private String materialCode;
@ExcelProperty("计量单位")
private String unit;
@ExcelProperty("电压等级")
private String voltageLevel;
@ExcelProperty("截面")
private int crossSection;
@ExcelProperty("芯数")
private int coreCount;
@ExcelProperty("联动原材料")
private String linkedMaterial;
@ExcelProperty("原材料型号")
private String rawMaterialModel;
@ExcelProperty(value = "K值系数(kg/计量单位)", index = 9)
private double kValueCopper;
@ExcelProperty(index = 10)
private double kValueAluminum;
// 构造函数、getter和setter方法...
}
import com.alibaba.excel.EasyExcel;
import java.io.File;
public class ExcelReader {
public static void main(String[] args) {
String filePath = "path/to/your/excel/file.xlsx"; // 替换为实际的文件路径
readExcel(filePath);
}
public static void readExcel(String filePath) {
File file = new File(filePath);
EasyExcel.read(file, CableData.class, new CableDataListener()).sheet().doRead();
}
}
class CableDataListener extends AnalysisEventListener<CableData> {
@Override
public void invoke(CableData data, AnalysisContext context) {
System.out.println(data); // 处理每一条数据
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
// 所有数据解析完成后执行的操作
}
}