所以我有这个程序读取一个excel文件并浏览C列单元并为每个目录创建一个新目录,在这些目录中创建一个文本文件,其中包含B列的内容。
我正在使用netbeans GUI构建器 所以我想添加一个进度条并将其链接到一个函数,这样当执行该函数时,进度条应该与它一起运行,当它完成时,进度条应该是100%
所以这是我的功能,任何人都可以帮助我吗?
public void CreateDir(String path) throws IOException {
try {
FileInputStream fis = new FileInputStream(path);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = wb.getSheetAt(0);
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
XSSFRow row = sheet.getRow(i);
XSSFCell cell = row.getCell(2);
//cell.setCellType(Cell.CELL_TYPE_STRING);
try {
if (cell != null) {
File dir = new File(getWorkSpacePath() + "\\" + cell);
// if the directory does not exist, create it
//System.out.println(Files.list(Paths.get(getWorkSpacePath()+dir.getName())).count());
if (!dir.exists()) {
try {
dir.mkdir();
} catch (SecurityException se) {
se.printStackTrace();
}
}
for (int j = i; j < sheet.getPhysicalNumberOfRows(); j++) {
File file = new File(getWorkSpacePath() + "\\" + dir.getName() + "\\" + sheet.getRow(i).getCell(0) + ".txt");
try {
PrintWriter writer = new PrintWriter(file);
writer.println(sheet.getRow(i).getCell(1).toString());
writer.close();
//System.out.println(Files.list(Paths.get(getWorkSpacePath() + "\\" + dir.getName())).count());
//countFilesInDirectory(getWorkSpaceFile());
} catch (IOException e) {
System.out.println("Error, " + e);
}