parent
f1ba2cc0e0
commit
6ebe2f2b95
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/YunNanDsBase.iml" filepath="$PROJECT_DIR$/.idea/YunNanDsBase.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,42 @@
|
||||
package com.dsideal.base.Tools.Excel;
|
||||
|
||||
|
||||
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) {
|
||||
int index = 0;
|
||||
for (int i = 0; i < columnLetter.length(); i++) {
|
||||
char c = columnLetter.charAt(i);
|
||||
if (c < 'A' || c > 'Z') {
|
||||
throw new IllegalArgumentException("无效的字母标号: " + columnLetter);
|
||||
}
|
||||
index = index * 26 + (c - 'A' + 1);
|
||||
}
|
||||
return index - 1; // 列索引从 0 开始
|
||||
}
|
||||
|
||||
// 将列索引转换为字母标号
|
||||
private static String indexToColumnLetter(int index) {
|
||||
StringBuilder columnLetter = new StringBuilder();
|
||||
while (index >= 0) {
|
||||
columnLetter.insert(0, (char) ('A' + (index % 26)));
|
||||
index = (index / 26) - 1;
|
||||
}
|
||||
return columnLetter.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.dsideal.base.Tools.Excel;
|
||||
|
||||
|
||||
import com.alibaba.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;
|
||||
}
|
Loading…
Reference in new issue