main
黄海 8 months ago
parent a4cc38002f
commit 6ff3d0188d

@ -28,7 +28,7 @@ public class A1 {
static String[] excludeCityList = {"~$", "磨憨-磨丁", "经开区", "阳宗海"}; static String[] excludeCityList = {"~$", "磨憨-磨丁", "经开区", "阳宗海"};
//有好多EXCEL啥样的有用必须带有关键字字样的才有用! //有好多EXCEL啥样的有用必须带有关键字字样的才有用!
static String fileNameKey="发展规模数据"; static String fileNameKey = "发展规模数据";
public static void main(String[] args) throws IOException, InvalidFormatException { public static void main(String[] args) throws IOException, InvalidFormatException {
//初始化数据库连接 //初始化数据库连接
@ -98,11 +98,9 @@ public class A1 {
List<List<String>> dataList = ExcelKit.readSecondTable(sourceExcel, 0, "自动计算招生数、在校生数", List<List<String>> dataList = ExcelKit.readSecondTable(sourceExcel, 0, "自动计算招生数、在校生数",
2, "K"); 2, "K");
//入园总数 //入园总数
for (List<String> stringList : dataList) { for (List<String> stringList : dataList){
//年份 //年份
if (stringList.isEmpty() || StrKit.isBlank(stringList.get(0))) break;
int year = Integer.parseInt(stringList.get(0)); int year = Integer.parseInt(stringList.get(0));
//3预测总招生数 //3预测总招生数
String zss = stringList.get(3).split("\\.")[0]; String zss = stringList.get(3).split("\\.")[0];
@ -124,7 +122,6 @@ public class A1 {
//城区 //城区
for (List<String> stringList : dataList) { for (List<String> stringList : dataList) {
//年份 //年份
if(stringList.isEmpty() || StrKit.isBlank(stringList.get(0))) break;
int year = Integer.parseInt(stringList.get(0)); int year = Integer.parseInt(stringList.get(0));
//4修正城区招生A //4修正城区招生A
int v = Integer.parseInt(stringList.get(4).split("\\.")[0]); int v = Integer.parseInt(stringList.get(4).split("\\.")[0]);
@ -136,7 +133,6 @@ public class A1 {
//镇区 //镇区
for (List<String> stringList : dataList) { for (List<String> stringList : dataList) {
if(stringList.isEmpty() || StrKit.isBlank(stringList.get(0))) break;
//年份 //年份
int year = Integer.parseInt(stringList.get(0)); int year = Integer.parseInt(stringList.get(0));
@ -149,10 +145,9 @@ public class A1 {
//乡村 //乡村
for (List<String> stringList : dataList) { for (List<String> stringList : dataList) {
if(stringList.isEmpty() || StrKit.isBlank(stringList.get(0))) break;
//年份 //年份
int year = Integer.parseInt(stringList.get(0)); int year = Integer.parseInt(stringList.get(0));
int v = Integer.parseInt(stringList.get(5).split("\\.")[0]); int v = Integer.parseInt(stringList.get(6).split("\\.")[0]);
Row outRow = outSheet.createRow(++rowIndex); Row outRow = outSheet.createRow(++rowIndex);
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year), ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year),
"", "乡村", "", String.valueOf(v), areaName, cityName), dataStyle); "", "乡村", "", String.valueOf(v), areaName, cityName), dataStyle);

@ -1,5 +1,6 @@
package com.dsideal.base.Tools.FillData.ExcelKit; package com.dsideal.base.Tools.FillData.ExcelKit;
import cn.hutool.core.util.NumberUtil;
import com.dsideal.base.DataEase.Model.ExcelReader; import com.dsideal.base.DataEase.Model.ExcelReader;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@ -176,15 +177,17 @@ public class ExcelKit {
workbook.close(); workbook.close();
return array; return array;
} }
public static String readCell(Cell cell){
return readCell(cell,""); public static String readCell(Cell cell) {
return readCell(cell, "");
} }
/** /**
* *
* *
* @param cell * @param cell
*/ */
public static String readCell(Cell cell,String defaultValue) { public static String readCell(Cell cell, String defaultValue) {
try { try {
// 根据单元格的类型来读取值 // 根据单元格的类型来读取值
switch (cell.getCellType()) { switch (cell.getCellType()) {
@ -230,7 +233,7 @@ public class ExcelKit {
// 其他类型的单元格 // 其他类型的单元格
return cell.toString(); return cell.toString();
} }
}catch (Exception err){ } catch (Exception err) {
return defaultValue; return defaultValue;
} }
} }
@ -580,10 +583,24 @@ public class ExcelKit {
} }
rowData.add(ExcelKit.readCell(cell)); rowData.add(ExcelKit.readCell(cell));
} }
dataList.add(rowData); if (!rowData.isEmpty()) dataList.add(rowData);
} }
workbook.close(); workbook.close();
fis.close(); fis.close();
//1、对于表格dataList,从后向前查找,发现是空行的就删除掉
//2、因为第一列都可以转为整数对于不能转为整数的从后向前遍历如果第一列不符合要求就直接去掉然后break
for (int i = dataList.size() - 1; i >= 0; i--) {
List<String> rowData = dataList.get(i);
if (rowData.isEmpty()) {
dataList.remove(i);
continue;
}
String firstCell = rowData.getFirst();
if (rowData.size() < tableWidth || !NumberUtil.isNumber(firstCell)) {
dataList.remove(i);
break;
}
}
return dataList; return dataList;
} }

Loading…
Cancel
Save