java基础
错误: 找不到或无法加载主类
参考:https://blog.csdn.net/qq_37958845/article/details/82420976
# CLASSPATH环境变量配置
.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
错误: 编码GBK的不可映射字符
# 编译时指定编码
javac -encoding UTF-8 test.java
java test
POI操作word、excel…
EasyPoi导入Excel
- 标题包含行、列合并单元格,具体列名重复,保存格式为List<Map
> ,重复列名数据丢失
1.导入Excel标题如图
EasyPoi4.2.0读取列名方法是,ExcelImportService.getTitleMap(…)
2.读取结果为:
…
高校教师资格证书发证单位(全称)
获奖日期(年月)
…
专业技术职务(最高)等级
名称(全称)
发证单位(全称)——————该标题由于Map的key不能重复,未读取
3.于是,修改ExcelImportService.getTitleMap(…)获取列名方式
读取结果为:**
高校教师资格证书发证单位(全称)
专业技术职务(最高)发证单位(全称)
//修改ExcelImportService.getTitleMap(...)
//368行
String value = getJoinCellValue(sheet, cell.getRowIndex(), cell.getColumnIndex(), 2);
/**
* 判断单元格是否是合并的单元格
* @param sheet
* @param row 单元格所在行
* @param column 单元格所在列
* @param type 合并:0,行合并:1,列合并:2
* @return
* @author chaijin
* @datetime 2020-08-26 15:29:00
*/
public JoinCellInfo isJoinCell(Sheet sheet, int row, int column, int type) {
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress range = sheet.getMergedRegion(i);
int firstRow = range.getFirstRow();
int lastRow = range.getLastRow();
int firstColumn = range.getFirstColumn();
int lastColumn = range.getLastColumn();
if (type == 1 && lastRow == firstRow) {
continue;
}
if (type == 2 && lastColumn == firstColumn) {
continue;
}
if(row >= firstRow && row <= lastRow){
if(column >= firstColumn && column <= lastColumn){
return new JoinCellInfo(true, firstRow, lastRow, firstColumn, lastColumn);
}
}
}
return new JoinCellInfo(false, 0, 0, 0, 0);
}
/**
* 获取单元格的值
* @param sheet
* @param row 单元格所在行
* @param column 单元格所在列
* @param type 合并:0,行合并:1,列合并:2
* @return
* @author chaijin
* @datetime 2020-08-26 15:29:00
*/
public String getJoinCellValue(Sheet sheet, int row, int column, int type) {
JoinCellInfo joinCell = isJoinCell(sheet, row, column, type);
if (joinCell.isJoinCell) {
row = joinCell.getFirstRow();
column = joinCell.getFirstColumn();
}
return sheet.getRow(row).getCell(column).getStringCellValue();
}
/*
合并单元格信息类
*/
class JoinCellInfo{
private boolean isJoinCell; //是否是合并单元格
private int firstRow; //合并开始行
private int lastRow; //合并结束行
private int firstColumn; //合并开始列
private int lastColumn; //合并结束列
public JoinCellInfo(boolean isJoinCell, int firstRow, int lastRow, int firstColumn, int lastColumn) {
this.isJoinCell = isJoinCell;
this.firstRow = firstRow;
this.lastRow = lastRow;
this.firstColumn = firstColumn;
this.lastColumn = lastColumn;
}
public boolean isJoinCell() {
return isJoinCell;
}
public void setJoinCell(boolean joinCell) {
isJoinCell = joinCell;
}
public int getFirstRow() {
return firstRow;
}
public void setFirstRow(int firstRow) {
this.firstRow = firstRow;
}
public int getLastRow() {
return lastRow;
}
public void setLastRow(int lastRow) {
this.lastRow = lastRow;
}
public int getFirstColumn() {
return firstColumn;
}
public void setFirstColumn(int firstColumn) {
this.firstColumn = firstColumn;
}
public int getLastColumn() {
return lastColumn;
}
public void setLastColumn(int lastColumn) {
this.lastColumn = lastColumn;
}
}