Commit a28c00ab by zhugs

feat:excel文件数据分析测试

parent 0916374e
......@@ -34,7 +34,7 @@ public class Main {
Path dirExcel = Path.of("C:\\Users\\zhugso\\Projects\\chenyang\\testdata\\exc");
Predicate<File> excelFilter = file -> {
String name = file.getName();
return !name.contains("$");
return !name.contains("$") && name.endsWith(".xlsx");
};
new DirWatcher(dirExcel, excelFilter, new ExcelHandlerFactory()).startWatch();
......
package execl;
import handler.AbstractFileHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@Slf4j
public class ExcelHandler extends AbstractFileHandler {
public ExcelHandler(File file) {
super(file);
}
@Override
protected void processFile(File file) {
try (FileInputStream fis = new FileInputStream(file);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fis)) {
String currentTestName;
int count = 0;
XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
for (int i = 0; i < lastRowNum + 1; i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
Cell firstCell = row.getCell(2);
if (firstCell == null) {
count = 0;
continue;
}
if (count == 0) {
currentTestName = firstCell.getStringCellValue().trim();
System.out.println(currentTestName);
} else {
Cell itemCell = row.getCell(2); // chain0 RSSI
Cell valueCell = row.getCell(3); // -69.0
Cell specCell = row.getCell(4); // (-75 <= x <= -65)
System.out.println(itemCell.getStringCellValue() + valueCell.getStringCellValue() + specCell.getStringCellValue());
}
count++;
} else {
count = 0;
}
}
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
package execl;
import handler.AbstractFileHandler;
import handler.FileHandlerFactory;
import java.io.File;
public class ExcelHandlerFactory implements FileHandlerFactory {
@Override
public AbstractFileHandler create(File file) {
return new ExcelHandler(file);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论