이 기사의 예는 POI를 사용하여 Java가 속성 파일을 읽고 Excel에 쓸 수있는 방법을 알려줍니다. 참조를 위해 모든 사람을 위해 공유하십시오. 특정 구현 방법은 다음과 같습니다.
com.hubberspot .util.iterator; .apache.poi.hssf.usermodel.hssfworkbook; import org.poi.hssf.util.hssfcolor; > (); public public void main (String [[String] args) {// readWritexlsProperties readWritexlsdemo = new readWritexlSpropers ()의 객체 작성 (); config.properties "); // call method writeexcel () 엑셀 파일로 경로를 가져옵니다. readritexlsdemo.writetoexcel ("test.xls ");} private void readProperties (string propertiesfilepath) {// path에서 취하는 파일 ct를 만듭니다. properties // file file propertiesfile = 새 파일 (propertiesfilepath); / / / / properties 파일은 아래에 do (propertiesfile.isfile ()) {// properties fileInputStream fisprop = new FileInputStream을로드하기 위해 fileInputStream을 만듭니다. (propertiesfile); // fileInputStream freperties를 통한 속성 및 value (); // 위의 속성 오버 메소드 위에 생성 된 // 열거 형식 열거 <boodge> keysenum = reperties.keys ()로 다시 반환합니다. 문자열 propkey = (string) keysenum.nextElement (); propmap.put (profkey.tolowercase () .trim (), propvalue.tologycase (). trim ());} // 파일 파일 파일을 닫는다. "ropmap); fisprop.close ();} catch (filenotfoundException e) {e.printstacktrace ();} catch (ioexception e) {e.printstacktrace ();}}} private voidoeeeexcel (string 엑셀 패스) {// HSSFRINGBOOK 객체 HSSFORKBOOK WORKBOOK을 사용하는 통합 문서 = 새로운 hssforkbook (); 호출 방법 // 워크 시트 hssfrow row = CreateCellStyle ()를 호출하여 셀 스타일을 만듭니다 hssfcellstyle의 setfillforegroundcolor () 및 setfillpattern.setfillforegroundcolor (hssfcolor.gold.index)를 통한 전경 및 채우기 패턴; hssfcell cell1 = row.createcell (0); 위에서 만든 스타일. havemap // keyset () 메소드를 호출하여 세트로 돌아갑니다 iterator while (iterator.hasnext ()) {// Worksheet에서 새 행을 생성 // 1 LocalFrow rowone = Worksheet.createrow (WorldSheet. getLastroPnum () +1); hssfcell cellzero = rowone.createcell. iterator.next (); try {fileoutstream fosexcel = xls filexcel 만들기 = fileoutstream fileout putstream (xls workbook.write). ); // 파일을 플러시하는 fosexcel.flush ();
이 기사는 모든 사람의 Java 프로그램 설계에 도움이되기를 바랍니다.