从txt输入并写入excel

时间:2017-07-19 11:43:51

标签: java

我正在为来自txt的输入数据编码JAVA,如果匹配则进行模式检查,然后将该值放入具有特定形式的xlsx文件中。并且输入文件数量超过一百..我怎样才能得到我想要的结果?请查看我的代码并帮助我 我想要的结果如下所示。(下面只是示例。真正的xlsx行超过100,000 the result I want

我得到的结果如下。 The result I got

我正在制作的java代码如下。

    File[] listFiles = dir.listFiles();
    for(File f: listFiles){
    if(f.isFile()){
        if(f.getName().contains(".log")){

           System.out.println("###"+f.getName()+"###");
           try{
             scan = new Scanner(f);
             int NE_CNT =1;
                 int Time_CNT =1;

                 Pattern NE_PT = Pattern.compile("(\\D{2})(\\d{1})(\\D{4,5})(\\d{3})");
             Pattern NE_TIME_PT = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2}) (\\D{3}) (\\d{2}):(\\d{2}):(\\d{2})");

            while(scan.hasNext()){  
              String Line = scan.nextLine();
            Matcher NE_MC = NE_PT.matcher(Line);
            Matcher NE_TIME_MC = NE_TIME_PT.matcher(Line);
            if(NE_MC.find()){
              row_NE = spreadsheet.createRow(NE_CNT);
              NE_CELL_DATA = row_NE.createCell(0);
              NE_CELL_DATA.setCellValue(NE_MC.group());
              NE_CNT++;
            }

            if(NE_TIME_MC.find()){
             row_Time = spreadsheet.createRow(Time_CNT);
             TIME_CELL_DATA = row_Time.createCell(1);
             TIME_CELL_DATA.setCellValue(NE_TIME_MC.group());
             Time_CNT++;        
            }           
        }       
      }catch(FileNotFoundException e){e.printStackTrace();}
    }
     }
   }
   workbook.write(out);
   out.close();
   workbook.close();
 }
}

0 个答案:

没有答案