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

网站下拉菜单重叠微信crm系统软件

网站下拉菜单重叠,微信crm系统软件,z-blog还是wordpress,一个软件开发需要什么技术java8循环追加Excel数据 实际遇到问题:定期获取zip文件,zip文件内有几个固定模板的Excel文件,有的Excel文件可能还包含多个sheet。 有段时间一次性获取到好几个zip包,需要将这些包都解压,并且按照不同的文件名、sheet进…

java8循环追加Excel数据


实际遇到问题:定期获取zip文件,zip文件内有几个固定模板的Excel文件,有的Excel文件可能还包含多个sheet。
有段时间一次性获取到好几个zip包,需要将这些包都解压,并且按照不同的文件名、sheet进行数据整合到一个sheet-Excel中。

![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/2f20c7a800c645f19d2f5e7d8d2edf01.png
在这里插入图片描述

可以在 pom.xml 中添加以下依赖:

<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>
<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version>
</dependency>
<dependency><groupId>org.apache.xmlbeans</groupId><artifactId>xmlbeans</artifactId><version>5.1.1</version>
</dependency>

import org.apache.poi.ss.usermodel.*;import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;public class ZipExcelMerger {public static void main(String[] args) {// 原始zip文件路径String zipDirectory = "path/to/zip/files";// 解压zip文件至新的路径String outputDirectory = "path/to/output";File dir = new File(zipDirectory);File[] zipFiles = dir.listFiles((d, name) -> name.endsWith(".zip"));if (zipFiles != null) {// 升序Collections.sort(Arrays.asList(zipDirectory));for (File zipFile : zipFiles) {unzipAndMerge(zipFile, outputDirectory);}}}private static void unzipAndMerge(File zipFile, String outputDirectory) {try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {ZipEntry entry;while ((entry = zis.getNextEntry()) != null) {if (!entry.isDirectory() && (entry.getName().endsWith(".xls") || entry.getName().endsWith(".xlsx"))) {File outputFile = new File(outputDirectory, entry.getName());byte[] buffer = new byte[1024];ByteArrayOutputStream baos = new ByteArrayOutputStream();int len;while ((len = zis.read(buffer)) > 0) {baos.write(buffer, 0, len);}baos.close();if (outputFile.exists()) {mergeExcelFiles(outputFile, new ByteArrayInputStream(baos.toByteArray()));} else {saveToFile(outputFile, new ByteArrayInputStream(baos.toByteArray()));}}}} catch (IOException e) {e.printStackTrace();}}private static void mergeExcelFiles(File existingFile, InputStream newFileStream) {File tempFile = null;try {// 创建临时文件tempFile = File.createTempFile("temp", ".xlsx");Files.copy(existingFile.toPath(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);// 读取临时文件Workbook existingWorkbook;try (InputStream is = new FileInputStream(tempFile)) {existingWorkbook = WorkbookFactory.create(is);}// 读取新文件try (Workbook newWorkbook = createWorkbook(newFileStream, existingFile.getName())) {for (int i = 0; i < newWorkbook.getNumberOfSheets(); i++) {Sheet newSheet = newWorkbook.getSheetAt(i);Sheet existingSheet = existingWorkbook.getSheet(newSheet.getSheetName());if (existingSheet != null) {for (int j = 1; j <= newSheet.getLastRowNum(); j++) {Row newRow = newSheet.getRow(j);if (newRow != null) {Row existingRow = existingSheet.createRow(existingSheet.getLastRowNum() + 1);copyRow(newRow, existingRow);}}}}}// 将合并后的内容写回临时文件try (OutputStream os = new FileOutputStream(tempFile)) {existingWorkbook.write(os);}// 用临时文件替换原文件Files.move(tempFile.toPath(), existingFile.toPath(), StandardCopyOption.REPLACE_EXISTING);} catch (IOException e) {e.printStackTrace();} finally {// 删除临时文件if (tempFile != null && tempFile.exists()) {tempFile.delete();}}}private static Workbook createWorkbook(InputStream inputStream, String fileName) throws IOException {if (fileName.endsWith(".xlsx")) {return WorkbookFactory.create(inputStream);} else if (fileName.endsWith(".xls")) {return WorkbookFactory.create(inputStream);} else {throw new IllegalArgumentException("Unsupported file format: " + fileName);}}private static void saveToFile(File file, InputStream inputStream) {try (FileOutputStream fos = new FileOutputStream(file)) {byte[] buffer = new byte[1024];int len;while ((len = inputStream.read(buffer)) > 0) {fos.write(buffer, 0, len);}} catch (IOException e) {e.printStackTrace();}}private static void copyRow(Row sourceRow, Row targetRow) {for (int i = 0; i < sourceRow.getLastCellNum(); i++) {Cell sourceCell = sourceRow.getCell(i);if (sourceCell != null) {Cell targetCell = targetRow.createCell(i);targetCell.setCellValue(sourceCell.toString());}}}
}
http://www.dtcms.com/wzjs/328444.html

相关文章:

  • 广州网站建设出售百度空间登录入口
  • 温州新闻网优化营商环境条例解读
  • 品牌购物网站十大排名深圳百度推广公司
  • wordpress 左侧福州短视频seo机会
  • 做网站西域数码阿里云小红书信息流广告投放
  • b2c电子商务网站需求分析今日实时热搜
  • 公司做网站的流程北京seo的排名优化
  • 手机app开发制作推荐青岛百度推广优化
  • 网站建设与搜索引擎营销有什么关系泉州百度竞价推广
  • 男孩做网站天津seo排名收费
  • 舟山的房子做民宿上什么网站高端网站设计
  • 海晏网站制作网易搜索引擎入口
  • 多地进一步优化防控措施宁波seo在线优化
  • 阿里云做的网站程序员域名权重
  • 东莞寮步网站设计怎么找关键词
  • 怎么做网站界面分析快速排名刷
  • 淘宝客的网站是怎么做的东莞做网站推广
  • 个性化网站建设公司电话社群营销的十大案例
  • phpstudy 网站空白软文案例
  • 四川省城乡建设厅监管网站专业北京网站建设公司
  • 企业级网站开发原理图深圳市网络营销推广服务公司
  • 达内网站开发国际网站平台有哪些
  • 北京王府井大楼百度seo文章
  • 做网站怎么切psd图百度引擎搜索
  • wordpress反应好慢东莞seo外包公司哪家好
  • 有支付功能网站用的编程语言哈尔滨企业网站模板建站
  • 太原建站公司点击查看嘉兴seo排名外包
  • wordpress与cms哪个好用seo网站排名优化公司哪家
  • 做网站卖链接今日nba比赛直播
  • wordpress公共函数在哪优化设计五年级下册语文答案