许鹏程
2023-06-29 8a45077cfa9c5ba734e91bca1ef7d88152ba5b47
src/main/java/com/product/lucene/util/FileUtils.java
@@ -14,6 +14,7 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -29,6 +30,7 @@
   /**
    *    文件转string
    *
    * @param file
    * @return
    */
@@ -52,6 +54,7 @@
   
   /**
    *    txt文件读取
    *
    * @param file
    * @return
    */
@@ -71,6 +74,7 @@
   
   /**
    *    doc转文本
    *
    * @param file
    * @return
    */
@@ -90,6 +94,7 @@
   
   /**
    *    docx转文本
    *
    * @param file
    * @return
    * @throws IOException
@@ -131,7 +136,8 @@
   
   /**
    * `xls转字符
    * @param f
    *
    * @param file
    * @return
    * @throws IOException
    */
@@ -140,8 +146,7 @@
      try(
         InputStream inputStream = new FileInputStream(file);
         HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream);
      )
      {
      ) {
         // Read the Sheet
         for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
            HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
@@ -168,6 +173,7 @@
   
   /**
    *    xlsx转字符
    *
    * @param file
    * @return
    * @throws IOException
@@ -204,33 +210,36 @@
   
   /**
    *    获取xls单元格值
    *
    * @param hssfCell
    * @return
    */
   private static String getValue(HSSFCell hssfCell) {
      if (hssfCell == null)
         return "";
      if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
      CellType cellType = hssfCell.getCellType();
      if (CellType.BOOLEAN.equals(cellType)) {
         return String.valueOf(hssfCell.getBooleanCellValue());
      } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
      } else if (CellType.NUMERIC.equals(cellType)) {
         return String.valueOf(hssfCell.getNumericCellValue());
      } else {
         hssfCell.setCellType(hssfCell.CELL_TYPE_STRING);
         return String.valueOf(hssfCell.getStringCellValue());
      }
   }
   
   /**
    *    获取xlxs单元格值
    *
    * @param xssfRow
    * @return
    */
   private static String getValue(XSSFCell xssfRow) {
      if (xssfRow == null)
         return "";
      if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
      CellType cellType = xssfRow.getCellType();
      if (CellType.BOOLEAN.equals(cellType)) {
         return String.valueOf(xssfRow.getBooleanCellValue());
      } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
      } else if (CellType.NUMERIC.equals(cellType)) {
         return String.valueOf(xssfRow.getNumericCellValue());
      } else {
         return String.valueOf(xssfRow.getStringCellValue());