|
|
@ -1,140 +1,140 @@
|
|
|
|
package com.sq.customization.bean;
|
|
|
|
//package com.sq.customization.bean;
|
|
|
|
|
|
|
|
//
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
//import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
//import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
//import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
//import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
//import java.util.List;
|
|
|
|
|
|
|
|
//
|
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
|
//import org.apache.poi.EncryptedDocumentException;
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
//import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
//import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
//import org.apache.poi.ss.usermodel.Row;
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
//import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
//import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
//import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
|
|
|
|
//
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
//import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
|
//import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
|
import com.sq.customization.util.ExcelUtil;
|
|
|
|
//import com.sq.customization.util.ExcelUtil;
|
|
|
|
|
|
|
|
//
|
|
|
|
public class ExcelBean {
|
|
|
|
//public class ExcelBean {
|
|
|
|
@ExcelProperty("工序信息")
|
|
|
|
// @ExcelProperty("工序信息")
|
|
|
|
private String bl_indented_title;
|
|
|
|
// private String bl_indented_title;
|
|
|
|
@ExcelProperty("紧固件号")
|
|
|
|
// @ExcelProperty("紧固件号")
|
|
|
|
private String item_id;
|
|
|
|
// private String item_id;
|
|
|
|
@ExcelProperty("SSVPPS")
|
|
|
|
// @ExcelProperty("SSVPPS")
|
|
|
|
private String SSVPPS;
|
|
|
|
// private String SSVPPS;
|
|
|
|
@ExcelProperty("FCC")
|
|
|
|
// @ExcelProperty("FCC")
|
|
|
|
private String FCC;
|
|
|
|
// private String FCC;
|
|
|
|
@ExcelProperty("动态扭矩")
|
|
|
|
// @ExcelProperty("动态扭矩")
|
|
|
|
private String dongtai;
|
|
|
|
// private String dongtai;
|
|
|
|
@ExcelProperty("KCDS")
|
|
|
|
// @ExcelProperty("KCDS")
|
|
|
|
private String KCDS;
|
|
|
|
// private String KCDS;
|
|
|
|
@ExcelProperty("头部形式")
|
|
|
|
// @ExcelProperty("头部形式")
|
|
|
|
private String headForm;
|
|
|
|
// private String headForm;
|
|
|
|
@ExcelProperty("头部尺寸")
|
|
|
|
// @ExcelProperty("头部尺寸")
|
|
|
|
private String headSize;
|
|
|
|
// private String headSize;
|
|
|
|
@ExcelProperty("工具组合")
|
|
|
|
// @ExcelProperty("工具组合")
|
|
|
|
private String alltool;
|
|
|
|
// private String alltool;
|
|
|
|
@ExcelProperty("工具")
|
|
|
|
// @ExcelProperty("工具")
|
|
|
|
private String SleeveResourceType;
|
|
|
|
// private String SleeveResourceType;
|
|
|
|
@ExcelProperty("套筒")
|
|
|
|
// @ExcelProperty("套筒")
|
|
|
|
private String ToolResourceType;
|
|
|
|
// private String ToolResourceType;
|
|
|
|
|
|
|
|
//
|
|
|
|
public ExcelBean() {}
|
|
|
|
// public ExcelBean() {}
|
|
|
|
|
|
|
|
//
|
|
|
|
public ExcelBean(String bl_indented_title, String item_id, String SSVPPS, String FCC, String dongtai,
|
|
|
|
// public ExcelBean(String bl_indented_title, String item_id, String SSVPPS, String FCC, String dongtai,
|
|
|
|
String KCDS, String headForm, String headSize, String alltool, String SleeveResourceType,
|
|
|
|
// String KCDS, String headForm, String headSize, String alltool, String SleeveResourceType,
|
|
|
|
String ToolResourceType) {
|
|
|
|
// String ToolResourceType) {
|
|
|
|
this.bl_indented_title = bl_indented_title;
|
|
|
|
// this.bl_indented_title = bl_indented_title;
|
|
|
|
this.item_id = item_id;
|
|
|
|
// this.item_id = item_id;
|
|
|
|
this.SSVPPS = SSVPPS;
|
|
|
|
// this.SSVPPS = SSVPPS;
|
|
|
|
this.FCC = FCC;
|
|
|
|
// this.FCC = FCC;
|
|
|
|
this.dongtai = dongtai;
|
|
|
|
// this.dongtai = dongtai;
|
|
|
|
this.KCDS = KCDS;
|
|
|
|
// this.KCDS = KCDS;
|
|
|
|
this.headForm = headForm;
|
|
|
|
// this.headForm = headForm;
|
|
|
|
this.headSize = headSize;
|
|
|
|
// this.headSize = headSize;
|
|
|
|
this.alltool = alltool;
|
|
|
|
// this.alltool = alltool;
|
|
|
|
this.SleeveResourceType = SleeveResourceType;
|
|
|
|
// this.SleeveResourceType = SleeveResourceType;
|
|
|
|
this.ToolResourceType = ToolResourceType;
|
|
|
|
// this.ToolResourceType = ToolResourceType;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
// Getter 和 Setter(保持不变,省略以节省篇幅)
|
|
|
|
// // Getter 和 Setter(保持不变,省略以节省篇幅)
|
|
|
|
|
|
|
|
//
|
|
|
|
public static void main(String[] args) {
|
|
|
|
// public static void main(String[] args) {
|
|
|
|
List<ExcelBean> data = Arrays.asList(
|
|
|
|
// List<ExcelBean> data = Arrays.asList(
|
|
|
|
new ExcelBean("工序1", "ID001", "SSVPPS1", "FCC1", "动态1", "KCDS1", "圆头", "10mm", "工具A", "工具类型1", "套筒1"),
|
|
|
|
// new ExcelBean("工序1", "ID001", "SSVPPS1", "FCC1", "动态1", "KCDS1", "圆头", "10mm", "工具A", "工具类型1", "套筒1"),
|
|
|
|
new ExcelBean("工序2", "ID002", "SSVPPS2", "FCC2", "动态2", "KCDS2", "平头", "12mm", "工具B", "工具类型2", "套筒2")
|
|
|
|
// new ExcelBean("工序2", "ID002", "SSVPPS2", "FCC2", "动态2", "KCDS2", "平头", "12mm", "工具B", "工具类型2", "套筒2")
|
|
|
|
);
|
|
|
|
// );
|
|
|
|
|
|
|
|
//
|
|
|
|
String fileName = "C:\\Users\\TEMP.CNSHI6P1090.000.001.002.003.004.005.006\\Desktop\\新建文件夹\\cust_rule_data.xlsx"; // 修改为可写路径
|
|
|
|
// String fileName = "C:\\Users\\TEMP.CNSHI6P1090.000.001.002.003.004.005.006\\Desktop\\新建文件夹\\cust_rule_data.xlsx"; // 修改为可写路径
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(fileName)) {
|
|
|
|
// try (FileOutputStream fos = new FileOutputStream(fileName)) {
|
|
|
|
EasyExcel.write(fos, ExcelBean.class)
|
|
|
|
// EasyExcel.write(fos, ExcelBean.class)
|
|
|
|
.sheet("Sheet1")
|
|
|
|
// .sheet("Sheet1")
|
|
|
|
.doWrite(data);
|
|
|
|
// .doWrite(data);
|
|
|
|
System.out.println("数据已成功导出到 " + fileName);
|
|
|
|
// System.out.println("数据已成功导出到 " + fileName);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// } catch (Exception e) {
|
|
|
|
System.err.println("导出失败: " + e.getMessage());
|
|
|
|
// System.err.println("导出失败: " + e.getMessage());
|
|
|
|
e.printStackTrace(); // 打印详细异常信息
|
|
|
|
// e.printStackTrace(); // 打印详细异常信息
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
// String filePath = "C:\\Users\\YourName\\Desktop\\cust_rule_data.xlsx"; // 替换为你的 Excel 文件路径
|
|
|
|
//// String filePath = "C:\\Users\\YourName\\Desktop\\cust_rule_data.xlsx"; // 替换为你的 Excel 文件路径
|
|
|
|
|
|
|
|
//
|
|
|
|
try (FileInputStream fis = new FileInputStream(fileName)) {
|
|
|
|
// try (FileInputStream fis = new FileInputStream(fileName)) {
|
|
|
|
// 使用 WorkbookFactory 自动适配 .xls 和 .xlsx
|
|
|
|
// // 使用 WorkbookFactory 自动适配 .xls 和 .xlsx
|
|
|
|
Workbook workbook = WorkbookFactory.create(fis);
|
|
|
|
// Workbook workbook = WorkbookFactory.create(fis);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 获取第一个工作表(Sheet1)
|
|
|
|
// // 获取第一个工作表(Sheet1)
|
|
|
|
Sheet sheet = workbook.getSheetAt(0); // 或使用 getSheet("Sheet1") 指定名称
|
|
|
|
// Sheet sheet = workbook.getSheetAt(0); // 或使用 getSheet("Sheet1") 指定名称
|
|
|
|
|
|
|
|
//
|
|
|
|
// 遍历所有行
|
|
|
|
// // 遍历所有行
|
|
|
|
for (Row row : sheet) {
|
|
|
|
// for (Row row : sheet) {
|
|
|
|
// 遍历每行中的单元格
|
|
|
|
// // 遍历每行中的单元格
|
|
|
|
for (Cell cell : row) {
|
|
|
|
// for (Cell cell : row) {
|
|
|
|
// 根据单元格类型读取数据
|
|
|
|
// // 根据单元格类型读取数据
|
|
|
|
String value = ExcelUtil.getStringCellValue(cell);
|
|
|
|
// String value = ExcelUtil.getStringCellValue(cell);
|
|
|
|
System.out.println(value);
|
|
|
|
// System.out.println(value);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
System.out.println(); // 每行结束后换行
|
|
|
|
// System.out.println(); // 每行结束后换行
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
// 关闭工作簿
|
|
|
|
// // 关闭工作簿
|
|
|
|
workbook.close();
|
|
|
|
// workbook.close();
|
|
|
|
System.out.println("Excel 文件读取完成");
|
|
|
|
// System.out.println("Excel 文件读取完成");
|
|
|
|
|
|
|
|
//
|
|
|
|
} catch (IOException e) {
|
|
|
|
// } catch (IOException e) {
|
|
|
|
System.err.println("读取 Excel 失败: " + e.getMessage());
|
|
|
|
// System.err.println("读取 Excel 失败: " + e.getMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
} catch (EncryptedDocumentException e) {
|
|
|
|
// } catch (EncryptedDocumentException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
} catch (InvalidFormatException e) {
|
|
|
|
// } catch (InvalidFormatException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
// Getter 和 Setter(以下为完整代码,之前省略的部分)
|
|
|
|
// // Getter 和 Setter(以下为完整代码,之前省略的部分)
|
|
|
|
public String getBl_indented_title() { return bl_indented_title; }
|
|
|
|
// public String getBl_indented_title() { return bl_indented_title; }
|
|
|
|
public void setBl_indented_title(String bl_indented_title) { this.bl_indented_title = bl_indented_title; }
|
|
|
|
// public void setBl_indented_title(String bl_indented_title) { this.bl_indented_title = bl_indented_title; }
|
|
|
|
public String getItem_id() { return item_id; }
|
|
|
|
// public String getItem_id() { return item_id; }
|
|
|
|
public void setItem_id(String item_id) { this.item_id = item_id; }
|
|
|
|
// public void setItem_id(String item_id) { this.item_id = item_id; }
|
|
|
|
public String getSSVPPS() { return SSVPPS; }
|
|
|
|
// public String getSSVPPS() { return SSVPPS; }
|
|
|
|
public void setSSVPPS(String SSVPPS) { this.SSVPPS = SSVPPS; }
|
|
|
|
// public void setSSVPPS(String SSVPPS) { this.SSVPPS = SSVPPS; }
|
|
|
|
public String getFCC() { return FCC; }
|
|
|
|
// public String getFCC() { return FCC; }
|
|
|
|
public void setFCC(String FCC) { this.FCC = FCC; }
|
|
|
|
// public void setFCC(String FCC) { this.FCC = FCC; }
|
|
|
|
public String getDongtai() { return dongtai; }
|
|
|
|
// public String getDongtai() { return dongtai; }
|
|
|
|
public void setDongtai(String dongtai) { this.dongtai = dongtai; }
|
|
|
|
// public void setDongtai(String dongtai) { this.dongtai = dongtai; }
|
|
|
|
public String getKCDS() { return KCDS; }
|
|
|
|
// public String getKCDS() { return KCDS; }
|
|
|
|
public void setKCDS(String KCDS) { this.KCDS = KCDS; }
|
|
|
|
// public void setKCDS(String KCDS) { this.KCDS = KCDS; }
|
|
|
|
public String getHeadForm() { return headForm; }
|
|
|
|
// public String getHeadForm() { return headForm; }
|
|
|
|
public void setHeadForm(String headForm) { this.headForm = headForm; }
|
|
|
|
// public void setHeadForm(String headForm) { this.headForm = headForm; }
|
|
|
|
public String getHeadSize() { return headSize; }
|
|
|
|
// public String getHeadSize() { return headSize; }
|
|
|
|
public void setHeadSize(String headSize) { this.headSize = headSize; }
|
|
|
|
// public void setHeadSize(String headSize) { this.headSize = headSize; }
|
|
|
|
public String getAlltool() { return alltool; }
|
|
|
|
// public String getAlltool() { return alltool; }
|
|
|
|
public void setAlltool(String alltool) { this.alltool = alltool; }
|
|
|
|
// public void setAlltool(String alltool) { this.alltool = alltool; }
|
|
|
|
public String getSleeveResourceType() { return SleeveResourceType; }
|
|
|
|
// public String getSleeveResourceType() { return SleeveResourceType; }
|
|
|
|
public void setSleeveResourceType(String SleeveResourceType) { this.SleeveResourceType = SleeveResourceType; }
|
|
|
|
// public void setSleeveResourceType(String SleeveResourceType) { this.SleeveResourceType = SleeveResourceType; }
|
|
|
|
public String getToolResourceType() { return ToolResourceType; }
|
|
|
|
// public String getToolResourceType() { return ToolResourceType; }
|
|
|
|
public void setToolResourceType(String ToolResourceType) { this.ToolResourceType = ToolResourceType; }
|
|
|
|
// public void setToolResourceType(String ToolResourceType) { this.ToolResourceType = ToolResourceType; }
|
|
|
|
}
|
|
|
|
//}
|
|
|
|