|
@@ -1,6 +1,9 @@
|
|
|
package com.winhc.task.util;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
|
|
|
+import com.winhc.task.bean.Company;
|
|
|
+import com.winhc.task.bean.Student;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
@@ -109,7 +112,7 @@ public class CsvToXlsxUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void csvToXLSxPlus(String csvFilePath, String xlsxFilePath,String sheetName) {
|
|
|
+ public static void csvToXLSxPlus(String csvFilePath, String xlsxFilePath, String sheetName) {
|
|
|
EasyExcelUtil easyExcelUtil = new EasyExcelUtil();
|
|
|
//easyExcelUtil.init(xlsxFilePath, sheet, head);
|
|
|
easyExcelUtil.init(xlsxFilePath, sheetName);
|
|
@@ -145,6 +148,42 @@ public class CsvToXlsxUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void jsonToXLSxPlus(String csvFilePath, String xlsxFilePath, String sheetName, List<List<String>> heads) {
|
|
|
+ EasyExcelUtil easyExcelUtil = new EasyExcelUtil();
|
|
|
+ easyExcelUtil.init(xlsxFilePath, sheetName, heads);
|
|
|
+ easyExcelUtil.init(xlsxFilePath, sheetName);
|
|
|
+ int RowNum = -1;
|
|
|
+ try {
|
|
|
+ File file = new File(csvFilePath);
|
|
|
+ InputStreamReader r = new InputStreamReader(new FileInputStream(file));
|
|
|
+ BufferedReader reader = new BufferedReader(r);
|
|
|
+ String content;
|
|
|
+ do {
|
|
|
+ RowNum++;
|
|
|
+ System.out.println(RowNum);
|
|
|
+ content = reader.readLine();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(content)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ List<Company> dataList = new ArrayList<>(1);
|
|
|
+ Company company = JSON.parseObject(content, Company.class);
|
|
|
+ dataList.add(company);
|
|
|
+ easyExcelUtil.doExportExcel(dataList);
|
|
|
+
|
|
|
+ } while (true);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("CsvToXlsxUtil exception :", e);
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ easyExcelUtil.finish();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("CsvToXlsxUtil close FileOutputStream exception :", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设置excel文件的sheet名称
|
|
|
* 获取CSV文件名作为Excel文件的sheet名称
|