main
HuangHai 4 months ago
parent a72958e8cf
commit 6a1bbf2fa4

@ -0,0 +1,31 @@
package com.dsideal.base.Tools.Excel.Bean;
import cn.idev.excel.annotation.ExcelProperty;
import com.dsideal.base.Tools.Excel.Util.ExcelUtil;
import lombok.Data;
@Data
public class School2019 {
@ExcelProperty(index = 1) // B列
private String schoolName;
@ExcelProperty(index = 3) // D列
private String schoolType;
@ExcelProperty(index = 5) // F列
private Integer schoolCount;
@ExcelProperty(index = 350) // MM列
private String city;
@ExcelProperty(index = 351) // MN列
private String district;
public static void main(String[] args) {
// 测试字母标号转列索引
String columnLetter = "MM"; // 示例输入
int columnIndex = ExcelUtil.columnLetterToIndex(columnLetter);
System.out.printf("字母标号 %s 对应的列索引是: %d%n", columnLetter, columnIndex);
}
}

@ -3,6 +3,7 @@ package com.dsideal.base.Tools.Excel;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import cn.idev.excel.*;
import com.dsideal.base.Tools.Excel.Bean.School2019;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
@ -16,18 +17,21 @@ public class ExcelReader {
excelLogger.setLevel(Level.INFO);
String filePath = "D:/dsWork/2025年收集的人口与教育数据库20250328/2015-2020年的数据/基础教育/2019.xlsx";
String sheetName = "基教小学";
//跳过前7行
int skipRows = 7;
// 从第8行开始读取跳过前7行
List<SchoolData> dataList = FastExcel.read(filePath)
.head(SchoolData.class)
List<School2019> dataList = FastExcel.read(filePath)
.head(School2019.class)
.sheet(sheetName)
.headRowNumber(7) // 跳过前7
.headRowNumber(skipRows) // 跳过前skipRows
.doReadSync();
// 使用 Map 进行分组统计
Map<String, Map<String, Integer>> cityDistrictMap = new HashMap<>();
for (SchoolData data : dataList) {
for (School2019 data : dataList) {
if (data.getSchoolCount() > 0) {
String city = data.getCity();
String district = data.getDistrict();

@ -1,23 +0,0 @@
package com.dsideal.base.Tools.Excel;
import cn.idev.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class SchoolData {
@ExcelProperty(index = 1) // B列
private String schoolName;
@ExcelProperty(index = 3) // D列
private String schoolType;
@ExcelProperty(index = 5) // F列
private Integer schoolCount;
@ExcelProperty(index = 350) // MM列
private String city;
@ExcelProperty(index = 351) // MN列
private String district;
}

@ -1,24 +1,9 @@
package com.dsideal.base.Tools.Excel;
package com.dsideal.base.Tools.Excel.Util;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
public class ExcelUtil {
public static void main(String[] args) {
// 设置 com.alibaba.excel 的日志级别为 INFO
Logger excelLogger = (Logger) LoggerFactory.getLogger("com.alibaba.excel");
excelLogger.setLevel(Level.INFO);
// 测试字母标号转列索引
String columnLetter = "MM"; // 示例输入
int columnIndex = columnLetterToIndex(columnLetter);
System.out.printf("字母标号 %s 对应的列索引是: %d%n", columnLetter, columnIndex);
}
// 将字母标号转换为列索引
private static int columnLetterToIndex(String columnLetter) {
public static int columnLetterToIndex(String columnLetter) {
int index = 0;
for (int i = 0; i < columnLetter.length(); i++) {
char c = columnLetter.charAt(i);
Loading…
Cancel
Save