|
|
|
@ -1,23 +1,24 @@
|
|
|
|
|
package UnitTest.ImportExcel;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class ImportExcelTemplate {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//告之配置文件位置
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
@ -38,22 +39,63 @@ public class ImportExcelTemplate {
|
|
|
|
|
FileInputStream file = new FileInputStream(filePath);
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(file);
|
|
|
|
|
|
|
|
|
|
List<List<List<String>>> allSheets = new ArrayList<>();
|
|
|
|
|
String sql = "truncate table t_zbdc_km CASCADE";
|
|
|
|
|
Db.update(sql);
|
|
|
|
|
sql = "truncate table t_zbdc_templet CASCADE";
|
|
|
|
|
Db.update(sql);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(i);
|
|
|
|
|
System.out.println("Sheet name: " + sheet.getSheetName());
|
|
|
|
|
String chineseString = "-仪器设备";
|
|
|
|
|
System.out.println("Sheet name: " + sheet.getSheetName().replace(chineseString, ""));
|
|
|
|
|
String km_name = sheet.getSheetName().replace(chineseString, "");
|
|
|
|
|
String km_code = PinyinUtil.getFirstLetter(km_name, ",").replace(",", "");
|
|
|
|
|
Record r1 = new Record();
|
|
|
|
|
r1.set("km_code", km_code);
|
|
|
|
|
r1.set("km_name", km_name);
|
|
|
|
|
|
|
|
|
|
if (km_name.startsWith("小学")) r1.set("stage_id", 4);
|
|
|
|
|
else if (km_name.startsWith("初中")) r1.set("stage_id", 5);
|
|
|
|
|
else r1.set("stage_id", 6);
|
|
|
|
|
Db.save("t_zbdc_km", "km_code", r1);
|
|
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
for (Row row : sheet) {
|
|
|
|
|
cnt++;
|
|
|
|
|
List<String> rowData = new ArrayList<>();
|
|
|
|
|
if (cnt == 1) System.out.println(row.getLastCellNum());
|
|
|
|
|
if (cnt == 1) continue;
|
|
|
|
|
for (Cell cell : row) {
|
|
|
|
|
cell.setCellType(CellType.STRING);
|
|
|
|
|
rowData.add(cell.getStringCellValue());
|
|
|
|
|
rowData.add(cell.getStringCellValue().replace("%","%%"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(rowData.size()<=9){
|
|
|
|
|
System.out.println("Here!");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//t_zbdc_templet
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
record.set("level_1", rowData.get(0));
|
|
|
|
|
record.set("level_2", rowData.get(1));
|
|
|
|
|
record.set("level_3", rowData.get(2));
|
|
|
|
|
record.set("level_4", rowData.get(3));
|
|
|
|
|
record.set("fldm", rowData.get(4));
|
|
|
|
|
record.set("mc", rowData.get(5));
|
|
|
|
|
record.set("ggxhgn", rowData.get(6));
|
|
|
|
|
record.set("dw", rowData.get(7));
|
|
|
|
|
record.set("ypsl", rowData.get(8));
|
|
|
|
|
record.set("bp", rowData.get(9));
|
|
|
|
|
record.set("xp", rowData.get(10));
|
|
|
|
|
try{
|
|
|
|
|
record.set("bz", rowData.get(11));
|
|
|
|
|
}
|
|
|
|
|
//System.out.println(rowData);
|
|
|
|
|
catch (Exception err){
|
|
|
|
|
record.set("bz", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record.set("km_code", km_code);
|
|
|
|
|
record.set("km_name", km_name);
|
|
|
|
|
Db.save("t_zbdc_templet", "templet_id", record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
workbook.close();
|
|
|
|
|