Excel如何查找两个名单相同或不同的姓名

打开excel数据表,我们有一个原始名单,还有一个实到名单。要找出两个名单中不同或相同的姓名。
在这里插入图片描述
按顺序操作,1选中数据——2条件格式——3突出显示单元格规则——4点击重复值,即可马上知道名单里的重复或者唯一值

可以使用 Apache POI 库来实现读取 Excel 格,并使用 Set 来判断是否存在两个相同。以下是示例代码: ```java import java.io.FileInputStream; import java.io.IOException; import java.util.HashSet; import java.util.Set; 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 ExcelReader { public static void main(String[] args) throws IOException { // 读取第一个 Excel 格 FileInputStream inputStream1 = new FileInputStream("excel1.xlsx"); Workbook workbook1 = WorkbookFactory.create(inputStream1); Sheet sheet1 = workbook1.getSheetAt(0); // 读取第二个 Excel 格 FileInputStream inputStream2 = new FileInputStream("excel2.xlsx"); Workbook workbook2 = WorkbookFactory.create(inputStream2); Sheet sheet2 = workbook2.getSheetAt(0); // 使用 Set 来存储姓名,判断是否存在相同 Set<String> names = new HashSet<>(); for (Row row : sheet1) { Cell cell = row.getCell(0); if (cell != null) { String name = cell.getStringCellValue(); names.add(name); } } for (Row row : sheet2) { Cell cell = row.getCell(0); if (cell != null) { String name = cell.getStringCellValue(); if (names.contains(name)) { System.out.println("存在相同:" + name); } } } // 关闭输入流和工作簿 inputStream1.close(); inputStream2.close(); workbook1.close(); workbook2.close(); } } ``` 其中,"excel1.xlsx" 和 "excel2.xlsx" 分别是要读取的两个 Excel 格,第一列是姓名。程序会输出存在相同姓名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大学生的计算机笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值