当前位置: 首页 > wzjs >正文

html5高端装修公司网站源码挖掘爱站网

html5高端装修公司网站源码,挖掘爱站网,福田建网站公司,番禺网站设计与制作新老数据的维护工具,例如:A文件有a、b、c列共十条数据,B文件有a、b、c、d列数据共15条数据(其中有包含A的一些数据)如何快速的将A里有的数据放入到B中(长点心吧!可别一条条比对着录入数据&#…

        新老数据的维护工具,例如:A文件有a、b、c列共十条数据,B文件有a、b、c、d列数据共15条数据(其中有包含A的一些数据)如何快速的将A里有的数据放入到B中(长点心吧!可别一条条比对着录入数据)

下面是一个完整的 Java 实现,

        使用 Apache POI 库处理 Excel 文件,对比 A、B 文件中的"测点标识"列(定位到相同的数据行),并将 A 文件中的"标签值"列填充到 B 文件对应的位置。

1. 添加 Maven 依赖
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.3</version>
</dependency>
<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version>
</dependency>
2. 完整代码实现
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;public class ExcelDataComparator {public static void main(String[] args) {String fileAPath = "path/to/FileA.xlsx";String fileBPath = "path/to/FileB.xlsx";String outputPath = "path/to/OutputFile.xlsx";try {// 1. 读取文件A的数据(测点标识 -> 标签值)Map<String, String> pointToTagMap = readFileA(fileAPath);// 2. 处理文件B并填充数据processFileB(fileBPath, outputPath, pointToTagMap);System.out.println("数据处理完成!输出文件: " + outputPath);} catch (Exception e) {e.printStackTrace();}}/*** 读取文件A,构建测点标识到标签值的映射*/private static Map<String, String> readFileA(String filePath) throws Exception {Map<String, String> map = new HashMap<>();FileInputStream fis = new FileInputStream(filePath);Workbook workbook = new XSSFWorkbook(fis);Sheet sheet = workbook.getSheetAt(0); // 假设使用第一个工作表// 获取表头行确定列索引Row headerRow = sheet.getRow(0);int pointIdIndex = -1;int tagValueIndex = -1;for (Cell cell : headerRow) {String headerName = cell.getStringCellValue().trim();if ("测点标识".equals(headerName)) {pointIdIndex = cell.getColumnIndex();} else if ("标签值".equals(headerName)) {tagValueIndex = cell.getColumnIndex();}}if (pointIdIndex == -1 || tagValueIndex == -1) {throw new RuntimeException("文件A中缺少必要的表头列");}// 遍历数据行for (int i = 1; i <= sheet.getLastRowNum(); i++) {Row row = sheet.getRow(i);if (row == null) continue;String pointId = getCellStringValue(row.getCell(pointIdIndex));String tagValue = getCellStringValue(row.getCell(tagValueIndex));if (pointId != null && !pointId.isEmpty()) {map.put(pointId, tagValue);}}workbook.close();fis.close();return map;}/*** 处理文件B并填充数据*/private static void processFileB(String inputPath, String outputPath, Map<String, String> pointToTagMap) throws Exception {FileInputStream fis = new FileInputStream(inputPath);Workbook workbook = new XSSFWorkbook(fis);Sheet sheet = workbook.getSheetAt(0);// 获取表头行确定列索引Row headerRow = sheet.getRow(0);int pointIdIndex = -1;int tagValueIndex = -1;for (Cell cell : headerRow) {String headerName = cell.getStringCellValue().trim();if ("测点标识".equals(headerName)) {pointIdIndex = cell.getColumnIndex();} else if ("标签值".equals(headerName)) {tagValueIndex = cell.getColumnIndex();}}if (pointIdIndex == -1) {throw new RuntimeException("文件B中缺少'测点标识'列");}// 如果文件B没有"标签值"列,可以创建(这里假设已有该列)if (tagValueIndex == -1) {tagValueIndex = headerRow.getLastCellNum();Cell newHeaderCell = headerRow.createCell(tagValueIndex);newHeaderCell.setCellValue("标签值");}// 遍历数据行并填充for (int i = 1; i <= sheet.getLastRowNum(); i++) {Row row = sheet.getRow(i);if (row == null) continue;String pointId = getCellStringValue(row.getCell(pointIdIndex));if (pointId == null || pointId.isEmpty()) continue;// 从文件A的映射中获取对应的标签值String tagValue = pointToTagMap.get(pointId);if (tagValue != null) {Cell targetCell = row.getCell(tagValueIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);targetCell.setCellValue(tagValue);}}// 保存修改后的文件FileOutputStream fos = new FileOutputStream(outputPath);workbook.write(fos);workbook.close();fos.close();}/*** 安全获取单元格字符串值*/private static String getCellStringValue(Cell cell) {if (cell == null) return "";switch (cell.getCellType()) {case STRING:return cell.getStringCellValue().trim();case NUMERIC:return String.valueOf((int) cell.getNumericCellValue());case BOOLEAN:return String.valueOf(cell.getBooleanCellValue());case FORMULA:return cell.getCellFormula();default:return "";}}
}

关键点说明

  1. 数据结构

    • 使用 Map<String, String> 存储文件A中的"测点标识"->"标签值"映射关系

  2. 列索引定位

    • 动态查找"测点标识"和"标签值"所在的列索引

  3. 单元格处理

    • getCellStringValue() 方法处理各种类型的单元格数据

    • 使用 Row.MissingCellPolicy.CREATE_NULL_AS_BLANK 处理可能为空的单元格

  4. 文件处理

    • 读取文件A构建映射关系

    • 读取文件B并修改数据

    • 输出到新文件(避免修改原始文件)

使用示例

假设:

  • 文件A.xlsx:

    测点标识标签值
    P001温度
    P002压力
  • 文件B.xlsx:

    测点标识其他数据标签值
    P001xxx
    P003yyy

运行程序后,输出文件将变为:

测点标识其他数据标签值
P001xxx温度
P003yyy

注意事项

  1. 文件格式支持:代码使用 .xlsx 格式(POI的XSSF)

  2. 性能优化:对于大文件,可以考虑使用 SXSSFWorkbook

  3. 错误处理:实际应用中应添加更完善的异常处理

  4. 表头检查:确保两个文件都有"测点标识"列

如果需要处理更复杂的情况(如多sheet、不同表头等),可以进一步扩展此代码。


文章转载自:

http://ohBEAjoQ.xmhpq.cn
http://Y6HxvVI4.xmhpq.cn
http://D0e3Bvv6.xmhpq.cn
http://EK0FjxzS.xmhpq.cn
http://xTUUFCfm.xmhpq.cn
http://vm1RUEiQ.xmhpq.cn
http://AiRtqWDB.xmhpq.cn
http://QTwL1fNs.xmhpq.cn
http://Du6qvHrY.xmhpq.cn
http://IInvb6Se.xmhpq.cn
http://p6VI5WkI.xmhpq.cn
http://qKvZ8vgG.xmhpq.cn
http://VibNyPOv.xmhpq.cn
http://AY52YEF4.xmhpq.cn
http://COqUpVwa.xmhpq.cn
http://0JLuKd9R.xmhpq.cn
http://fmAFkQip.xmhpq.cn
http://dfm0MOWi.xmhpq.cn
http://Oq79cqkj.xmhpq.cn
http://P0GDI48R.xmhpq.cn
http://nuKgpRdw.xmhpq.cn
http://VA2rGxDT.xmhpq.cn
http://ZtCxZhL7.xmhpq.cn
http://aLzYiZS0.xmhpq.cn
http://3EQWoNPx.xmhpq.cn
http://eLjojumA.xmhpq.cn
http://WmLlBy3N.xmhpq.cn
http://NXeX2R7I.xmhpq.cn
http://eZaCxCYq.xmhpq.cn
http://AXVVrCBF.xmhpq.cn
http://www.dtcms.com/wzjs/699141.html

相关文章:

  • 有哪些做公司网站的徐汇网站制作设计
  • 科技公司注册需要什么条件网站页面优化
  • 360网站导航公司地址怎么做潍坊营销网站
  • 包头网站建设兼职wordpress添加小人
  • 做网站用什么虚拟主机宿州市做网站的公司
  • 网站把域名解析到新ip后地方门户类网站
  • 艺缘网站的建设网站开发程序都有什么
  • 西安网站优化seo郑州最新公告
  • 网站ico图标怎么做四川达州网站建设
  • 网站建设分为展示型网站建设和网站优化的区别
  • 自己做网站 最好的软件抖音优化排名
  • 成都装饰公司网站建设wordpress ping服务插件
  • 上海金融网站建设公司装修网页设计
  • 如何做喊单网站网络哪个公司好
  • 学校网站方案wordpress开启xmlrppc
  • 快速知彼网络网站建设微信网页版怎么扫描二维码
  • wordpress海外建站石家庄网站建设网站
  • 软件编程代码大全seo怎么做网站排名
  • 制作网站要多少钱wordpress 页面 权限
  • 做不做我女朋友的网站做书封面的模板下载网站
  • WordPress主题设置数据库六安seo地址
  • 营销型网站与展示型网站wordpress qqkf
  • 手机建网站推广广东东莞人才网招聘网
  • 嘉峪关网站建设html5网页代码大全
  • 经典重庆网站WordPress页面批量生成
  • 哪些网站国内打不开网上青年团智慧团建登录
  • 黄金网站app视频工信部网站备案登录
  • 国外有哪些网站做推广的比较好上海求职网招聘网
  • 惠州网站建设哪里找北京全网推广
  • 做网站推广的工作好吗网站建设辅助