해당 열 중 하나에 파일 이름이 많은 Excel 파일이 있습니다. 내가 그 파일 이름을 읽고 destination.Can 하나를 도와 줄 수있는 동일한 생성해야 자바 코드를 작성해야합니까?엑셀 시트를 읽음으로써 파일 생성
0
A
답변
0
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Test {
public static void main(String[] args) throws IOException {
try {
FileInputStream file = new FileInputStream(new File("C:\\test.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows from first sheet
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()) {
Row row = rowIterator.next();
//For each row, iterate through each columns
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
Cell cell = cellIterator.next();
System.out.print(cell.getStringCellValue() + "\t\t");
FileOutputStream outFile =new FileOutputStream(new File("C:\\"+cell.getStringCellValue()));
workbook.write(outFile);
}
System.out.println("");
}
file.close();
/* FileOutputStream outFile =new FileOutputStream(new File("C:\\update.xls"));
workbook.write(outFile);*/
//outFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
+0
안녕하세요, 정말 도움이되었습니다. 고마워 ... :) – GanStack
0
엑셀 파일을 읽을 때 사용할 수있는 라이브러리가 있습니다. 제 경우에는 무료로 다운로드하여 프로젝트에 추가 할 수있는 Apache POI을 선택했습니다.
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream("filename.xlsx"));
지금 당신이 각 행을 반복하고 첫 번째 열을 읽을 수 있습니다 : 나중에 2007 또는에서 엑셀 문서의 경우,
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("filename.xls"));
또는 : 당신이 그것을 추가되면, 귀하의 문서를 만들
for(Row row : workbook.getSheetAt(0)) // Go through each row in sheet 0
System.out.println(row.getCell(0).getStringCellValue());
+0
당신의 소중한 아이디어에 감사드립니다. 나는 그것을 사용할 것이다 .. .. :) – GanStack
0
공용 클래스 테스트 {
public static void main(String[] args) throws IOException {
try {
FileInputStream file = new FileInputStream(new File("D:\\sampleFileNames.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
FileOutputStream outFile= null;
HSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows from first sheet
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()) {
Row row = rowIterator.next();
//For each row, iterate through each columns
Iterator<Cell> cellIterator = row.cellIterator();
Cell cell = cellIterator.next();
File file1 = new File("D:\\Ganesh\\"+cell.getStringCellValue().toString());
if(!file1.createNewFile()) {
System.out.println("File already exists");
/* Cell cell = cellIterator.next();
System.out.print(cell.getStringCellValue() + "\t\t");
outFile =new FileOutputStream(new File("D:\\Ganesh\\"+cell.getStringCellValue().toString()));
//workbook.write(outFile);
System.out.println("");
}
file.close();
outFile.close();
/* FileOutputStream outFile =new FileOutputStream(new File("C:\\update.xls"));
workbook.write(outFile);*/
//outFile.close();
}
}
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
,
} }
관련 문제
- 1. 나는 엑셀 시트를 생성 할
- 2. 엑셀 시트를 통해 MatLab에서 함수 생성
- 3. 유닉스 : 시트를 엑셀 파일 이름과 위치
- 4. 엑셀 스프레드 시트를 분리하여 별도의 엑셀 시트를 행별로 구분하는 방법
- 5. 엑셀 시트를 양식에 넣으십시오.
- 6. 엑셀 시트를 선택하십시오.
- 7. 엑셀 시트를 숨기는 부분
- 8. 엑셀 시트를 열려면 어떻게해야합니까?
- 9. 안드로이드에 엑셀 시트를 만듭니다
- 10. 엑셀 시트를 mongo에 업로드하십시오.
- 11. 엑셀 시트를 엑셀에 삽입하기
- 12. 엑셀 파일 생성 및 다운로드
- 13. 엑셀 파일에서 mxml 파일 생성
- 14. 정렬 순서가 역순으로 생성 된 시간을 기준으로/엑셀 시트를 반대로
- 15. 엑셀 시트를 생성 할 때 그리드보기 템플릿 필드가 필요하지 않습니다.
- 16. 여러 엑셀 시트를 만드는 방법
- 17. 엑셀 시트를 mysql 데이터베이스로 액세스
- 18. 엑셀 스프레드 시트를 HTML로 변환
- 19. 엑셀 시트를 조작하기위한 파이썬 스크립트
- 20. 엑셀 시트를 읽는 이유는 무엇입니까?
- 21. 엑셀 워크 시트를 mvc.net에서 읽으십시오.
- 22. 데이터베이스에서 엑셀 시트를 생성하는 중
- 23. 장고 - 엑셀 파일 읽기
- 24. 엑셀 생성
- 25. 엑셀 시트를 열려면 xlwt를 내 보냅니다.
- 26. 복사 데이터 시트를 엑셀 및 VBScript를
- 27. 은 즉시 시트를 엑셀 쓰기 xlwt
- 28. PHPExcel을 사용하여 자동 생성 엑셀 파일
- 29. PHP 엑셀 생성 - 잘못된 파일 형식
- 30. 엑셀 파일 저장 새로 생성 된 폴더로
코드를 공유하십시오 ... – Biswajit