| | |
| | | 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; |
| | |
| | | |
| | | /** |
| | | * 文件转string |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * txt文件读取 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * doc转文本 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * docx转文本 |
| | | * |
| | | * @param file |
| | | * @return |
| | | * @throws IOException |
| | |
| | | |
| | | /** |
| | | * `xls转字符 |
| | | * @param f |
| | | * |
| | | * @param file |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | |
| | | 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); |
| | |
| | | |
| | | /** |
| | | * xlsx转字符 |
| | | * |
| | | * @param file |
| | | * @return |
| | | * @throws IOException |
| | |
| | | |
| | | /** |
| | | * 获取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()); |