java基础

错误: 找不到或无法加载主类

参考:https://blog.csdn.net/qq_37958845/article/details/82420976

  1. # CLASSPATH环境变量配置
  2. .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar

错误: 编码GBK的不可映射字符

  1. # 编译时指定编码
  2. javac -encoding UTF-8 test.java
  3. java test

POI操作word、excel…

EasyPoi导入Excel

  • 标题包含行、列合并单元格,具体列名重复,保存格式为List<Map> ,重复列名数据丢失

1.导入Excel标题如图
image.png

EasyPoi4.2.0读取列名方法是,ExcelImportService.getTitleMap(…)

2.读取结果为:

高校教师资格证书发证单位(全称)
获奖日期(年月)

专业技术职务(最高)
等级
名称(全称)
发证单位(全称)——————该标题由于Map的key不能重复,未读取

3.于是,修改ExcelImportService.getTitleMap(…)获取列名方式

读取结果为:**
高校教师资格证书发证单位(全称)
专业技术职务(最高)
发证单位(全称)

  1. //修改ExcelImportService.getTitleMap(...)
  2. //368行
  3. String value = getJoinCellValue(sheet, cell.getRowIndex(), cell.getColumnIndex(), 2);
  4. /**
  5. * 判断单元格是否是合并的单元格
  6. * @param sheet
  7. * @param row 单元格所在行
  8. * @param column 单元格所在列
  9. * @param type 合并:0,行合并:1,列合并:2
  10. * @return
  11. * @author chaijin
  12. * @datetime 2020-08-26 15:29:00
  13. */
  14. public JoinCellInfo isJoinCell(Sheet sheet, int row, int column, int type) {
  15. int sheetMergeCount = sheet.getNumMergedRegions();
  16. for (int i = 0; i < sheetMergeCount; i++) {
  17. CellRangeAddress range = sheet.getMergedRegion(i);
  18. int firstRow = range.getFirstRow();
  19. int lastRow = range.getLastRow();
  20. int firstColumn = range.getFirstColumn();
  21. int lastColumn = range.getLastColumn();
  22. if (type == 1 && lastRow == firstRow) {
  23. continue;
  24. }
  25. if (type == 2 && lastColumn == firstColumn) {
  26. continue;
  27. }
  28. if(row >= firstRow && row <= lastRow){
  29. if(column >= firstColumn && column <= lastColumn){
  30. return new JoinCellInfo(true, firstRow, lastRow, firstColumn, lastColumn);
  31. }
  32. }
  33. }
  34. return new JoinCellInfo(false, 0, 0, 0, 0);
  35. }
  36. /**
  37. * 获取单元格的值
  38. * @param sheet
  39. * @param row 单元格所在行
  40. * @param column 单元格所在列
  41. * @param type 合并:0,行合并:1,列合并:2
  42. * @return
  43. * @author chaijin
  44. * @datetime 2020-08-26 15:29:00
  45. */
  46. public String getJoinCellValue(Sheet sheet, int row, int column, int type) {
  47. JoinCellInfo joinCell = isJoinCell(sheet, row, column, type);
  48. if (joinCell.isJoinCell) {
  49. row = joinCell.getFirstRow();
  50. column = joinCell.getFirstColumn();
  51. }
  52. return sheet.getRow(row).getCell(column).getStringCellValue();
  53. }
  54. /*
  55. 合并单元格信息类
  56. */
  57. class JoinCellInfo{
  58. private boolean isJoinCell; //是否是合并单元格
  59. private int firstRow; //合并开始行
  60. private int lastRow; //合并结束行
  61. private int firstColumn; //合并开始列
  62. private int lastColumn; //合并结束列
  63. public JoinCellInfo(boolean isJoinCell, int firstRow, int lastRow, int firstColumn, int lastColumn) {
  64. this.isJoinCell = isJoinCell;
  65. this.firstRow = firstRow;
  66. this.lastRow = lastRow;
  67. this.firstColumn = firstColumn;
  68. this.lastColumn = lastColumn;
  69. }
  70. public boolean isJoinCell() {
  71. return isJoinCell;
  72. }
  73. public void setJoinCell(boolean joinCell) {
  74. isJoinCell = joinCell;
  75. }
  76. public int getFirstRow() {
  77. return firstRow;
  78. }
  79. public void setFirstRow(int firstRow) {
  80. this.firstRow = firstRow;
  81. }
  82. public int getLastRow() {
  83. return lastRow;
  84. }
  85. public void setLastRow(int lastRow) {
  86. this.lastRow = lastRow;
  87. }
  88. public int getFirstColumn() {
  89. return firstColumn;
  90. }
  91. public void setFirstColumn(int firstColumn) {
  92. this.firstColumn = firstColumn;
  93. }
  94. public int getLastColumn() {
  95. return lastColumn;
  96. }
  97. public void setLastColumn(int lastColumn) {
  98. this.lastColumn = lastColumn;
  99. }
  100. }