From 869811937c43668d75a34e3df385b966f1afc71b Mon Sep 17 00:00:00 2001 From: lroyia Date: Tue, 7 May 2024 16:04:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0xlsx=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=9A=84=E8=BE=93=E5=87=BA=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 18 ++++++++++++++++++ src/main/java/io/lroyia/ApplicationRun.java | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8ebb3c9..e19f50a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,24 @@ poi 4.1.2 + + + org.apache.poi + poi-ooxml + 4.1.2 + + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + + org.apache.poi + poi-scratchpad + 4.1.2 + diff --git a/src/main/java/io/lroyia/ApplicationRun.java b/src/main/java/io/lroyia/ApplicationRun.java index b0edd83..12dd4a8 100644 --- a/src/main/java/io/lroyia/ApplicationRun.java +++ b/src/main/java/io/lroyia/ApplicationRun.java @@ -3,10 +3,10 @@ package io.lroyia; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; 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.xssf.usermodel.XSSFWorkbook; import java.io.File; import java.io.FileOutputStream; @@ -41,12 +41,12 @@ public class ApplicationRun { } File file = new File(fileUri); String fileName = file.getName(); - String newFileName = fileName.replace(".csv", ".xls"); + String newFileName = fileName.replace(".csv", ".xlsx"); try(CSVParser csv = CSVParser.parse(file, Charset.forName(chartSet), CSVFormat.DEFAULT); OutputStream os = new FileOutputStream(newFileName)){ List headerNames = csv.getHeaderNames(); System.out.println(headerNames); - HSSFWorkbook workbook = new HSSFWorkbook(); + XSSFWorkbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(); Row header = sheet.createRow(0); int colLength = headerNames.size();