main
黄海 10 months ago
parent 9c512951ff
commit 07487ddf95

@ -0,0 +1,52 @@
package com.dsideal.base.Tools;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.jfinal.plugin.activerecord.Record;
import java.io.File;
import java.util.*;
public class DataTransformer {
public static void main(String[] args) {
String input = "D:\\dsWork\\dsProject\\dsBase\\src\\main\\java\\com\\dsideal\\base\\Tools\\Sample.xlsx";
File file = new File(input);
//哪些列是固定不动的,比如此处是第0列与第1列是不动的就是年份+学段
List<Integer> fixedColumns = new ArrayList<>();
fixedColumns.add(0);
fixedColumns.add(1);
//每列的列号与列名对应关系
String[] colNames = new String[1024];
int cl = 0;
// 读取Excel数据
ExcelReader reader = ExcelUtil.getReader(file);
//表头
List<List<Object>> read = reader.read(0, 0);//第0行是表头
for (int i = 0; i < reader.getColumnCount(); i++) {
colNames[cl++] = read.getFirst().get(i).toString();
}
//数据
List<List<Object>> data = reader.read(1, reader.getRowCount());//从第1行读取到最后一行
for (List<Object> row : data) {
//拆分每一行的数据
for (int i = 0; i < reader.getColumnCount(); i++) {
if (!fixedColumns.contains(i)) {//非fixedColumns列进行枚举
for (int cNum : fixedColumns) {
String cName = colNames[cNum];//列名
String value = row.get(cNum).toString();//列值
System.out.print(cName + ":" + value+" ");
}
String cName = colNames[i];//列名
String value = row.get(i).toString();
System.out.print(cName + ":" + value);
System.out.println();
}
}
}
}
}

@ -2,6 +2,8 @@
uploadTempPath: c:/Windows/Temp
# JWT
SECRET: ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM
# 生成Token的密码
CookieMd5SingPwd: DsideaL4r5t6y7u
mysql:
# 数据库信息
@ -17,9 +19,6 @@ redis:
password:
# ==============================================================
jwt:
# 生成Token的密码
CookieMd5SingPwd: DsideaL4r5t6y7u
excel:
# 导出excel 的模板配置路径

@ -2,6 +2,8 @@
uploadTempPath: /tmp
# JWT
SECRET: ZXZnZWVr5b+r5LmQ5L2g55qE5Ye66KGM
# 生成Token的密码
CookieMd5SingPwd: DsideaL4r5t6y7u
mysql:
# 数据库信息

Loading…
Cancel
Save