git查看用户
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package com.budwk.app.base.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author FKY
|
||||
* @name:FileExcelUtil
|
||||
* @Date 2026/1/31 15:33
|
||||
* @注释
|
||||
*/
|
||||
@Slf4j
|
||||
public class FileExcelUtil {
|
||||
|
||||
public static Map<String, String> readExcelTable(File file){
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
Workbook workbook = new XSSFWorkbook(fis);
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
// 遍历所有行
|
||||
for (Row row : sheet) {
|
||||
int rowColumnIndex = 0 ;
|
||||
String keyName = "";
|
||||
String keyValue = "";
|
||||
|
||||
// 遍历所有单元格
|
||||
for (Cell cell : row) {
|
||||
String cellValue = String.valueOf(getCellValue(cell));
|
||||
|
||||
log.info("| " + cellValue + " ");
|
||||
|
||||
if((rowColumnIndex % 2) <= 0) {
|
||||
keyName = cellValue;
|
||||
} else {
|
||||
keyValue = cellValue;
|
||||
}
|
||||
if(StrUtil.isNotBlank(keyName) && StrUtil.isNotBlank(keyValue)) {
|
||||
if(keyName.contains("*")) {
|
||||
keyName = keyName.replace("*", "");
|
||||
}
|
||||
dataMap.put(keyName, keyValue);
|
||||
keyName = "";
|
||||
keyValue = "";
|
||||
}
|
||||
rowColumnIndex ++;
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static Object getCellValue(Cell cell) {
|
||||
CellType cellType = cell.getCellType();
|
||||
|
||||
if (cellType == CellType.FORMULA) {
|
||||
cellType = cell.getCachedFormulaResultType();
|
||||
}
|
||||
|
||||
switch (cellType) {
|
||||
case STRING:
|
||||
return cell.getStringCellValue();
|
||||
case NUMERIC:
|
||||
if (isCellDateType(cell)) {
|
||||
return cell.getDateCellValue();
|
||||
}
|
||||
return cell.getNumericCellValue();
|
||||
case BOOLEAN:
|
||||
return cell.getBooleanCellValue();
|
||||
case BLANK:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean isCellDateType(Cell cell) {
|
||||
try {
|
||||
cell.getDateCellValue();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.budwk.app.base.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author FKY
|
||||
* @name:FileWordUtil
|
||||
* @Date 2026/1/31 15:01
|
||||
* @注释
|
||||
*/
|
||||
@Slf4j
|
||||
public class FileWordUtil {
|
||||
|
||||
public static List<Map<String, String>> readWordTable(File file) {
|
||||
List<Map<String, String>> dataMaps = new ArrayList<>();
|
||||
try{
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
XWPFDocument document = new XWPFDocument(fis);
|
||||
|
||||
// 获取所有表格
|
||||
List<XWPFTable> tables = document.getTables();
|
||||
log .info("文档中共有 " + tables.size() + " 个表格");
|
||||
|
||||
// 遍历每个表格
|
||||
for (int t = 0; t < tables.size(); t++) {
|
||||
log.info("\n--- 表格 " + (t + 1) + " ---");
|
||||
XWPFTable table = tables.get(t);
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
|
||||
// 遍历表格的每一行
|
||||
for (XWPFTableRow row : table.getRows()) {
|
||||
int rowColumnIndex = 0 ;
|
||||
String keyName = "";
|
||||
String keyValue = "";
|
||||
// 遍历行中的每个单元格
|
||||
for (XWPFTableCell cell : row.getTableCells()) {
|
||||
// 获取单元格文本并打印
|
||||
String cellText = cell.getText();
|
||||
log.info("| " + cellText + " ");
|
||||
if((rowColumnIndex % 2) <= 0) {
|
||||
keyName = cellText;
|
||||
} else {
|
||||
keyValue = cellText;
|
||||
}
|
||||
if(StrUtil.isNotBlank(keyName) && StrUtil.isNotBlank(keyValue)) {
|
||||
if(keyName.contains("*")) {
|
||||
keyName = keyName.replace("*", "");
|
||||
}
|
||||
|
||||
dataMap.put(keyName, keyValue);
|
||||
keyName = "";
|
||||
keyValue = "";
|
||||
}
|
||||
rowColumnIndex ++;
|
||||
}
|
||||
log.info("|"); // 换行
|
||||
}
|
||||
if(!dataMap.isEmpty()){
|
||||
dataMaps.add(dataMap);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("读取word文件出错",e);
|
||||
}
|
||||
return dataMaps;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user