0
int temp = 7;
File folder = new File("//Users//" + usr + "//Desktop//TNA//input1//");
File[] listOfFiles = folder.listFiles();
if (listOfFiles != null) {
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile() && (listOfFiles[i].getName()).endsWith(".pdf")) {
System.out.println(listOfFiles[i].getName());
String fileName = "//Users//" + usr + "//Desktop//TNA//input1//" + listOfFiles[i].getName();
try {
PdfReader reader = new PdfReader("//Users//gmuniandy//Desktop//TNA//input1//" + listOfFiles[i].getName());
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2));
AcroFields form = stamper.getAcroFields();
String name = form.getField("Text1");//Check Box 1
System.out.println(name);
stamper.close();
reader.close();
FileInputStream file = new FileInputStream(new File("//Users//"+ usr +"//Desktop//TNA//input//FR-OPS-030 Master Training Plan_Rev4.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheet("Sheet1");// getSheetAt(0);
HSSFRow row = sheet.createRow((short) 0);
HSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(HSSFColor.DARK_BLUE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFRow row1 = sheet.createRow(temp);
HSSFCell name_c1 = row1.createCell(0);
name_c1.setCellValue(name);
name_c1.setCellStyle(style);
file.close();
FileOutputStream outFile =new FileOutputStream(new File("//Users//"+ usr +"//Desktop//TNA//output//FR-OPS-030 Master Training Plan_Rev41w.xls"));
workbook.write(outFile);
outFile.close();
temp++;
} catch (Exception ex) {
}
}
}
}
나는 PDF
에서 값을 검색하고 Excel
에 글을 씁니다. 나는 Excel
에 글을 쓸 수 있었지만, 마지막으로 업데이트 된 데이터는 Excel
에 업데이트되었습니다. 제 잘못을 조언 해주세요.Java - Write 마지막 데이터 만 쓰기
if (listOfFiles[i].isFile() && (listOfFiles[i].getName()).endsWith(".pdf")) {
System.out.println(listOfFiles[i].getName());
String fileName = "//Users//" + usr + "//Desktop//TNA//input1//" + listOfFiles[i].getName();
FileInputStream file = new FileInputStream(new File("//Users//"+ usr +"//Desktop//TNA//input//FR-OPS-030 Master Training Plan_Rev4.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
try {
PdfReader reader = new PdfReader("//Users//gmuniandy//Desktop//TNA//input1//" + listOfFiles[i].getName());
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2));
AcroFields form = stamper.getAcroFields();
String name = form.getField("Text1");//Check Box 1
System.out.println(name);
stamper.close();
reader.close();
HSSFSheet sheet = workbook.getSheet("Sheet1");// getSheetAt(0);
HSSFRow row = sheet.createRow((short) 0);
HSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(HSSFColor.DARK_BLUE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFRow row1 = sheet.createRow(temp);
HSSFCell name_c1 = row1.createCell(0);
name_c1.setCellValue(name);
name_c1.setCellStyle(style);
file.close();
temp++;
} catch (Exception ex) {
}
finally{
FileOutputStream outFile =new FileOutputStream(new File("//Users//"+ usr +"//Desktop//TNA//output//FR-OPS-030 Master Training Plan_Rev41w.xls"));
workbook.write(outFile);
outFile.close();
}
EDIT 심지어 나는이 시도하지만, 단지 같은.