この記事の例は、POIを使用してPropertiesファイルを読み取り、Excelに書き込みます。あなたの参照のために全員のためにそれを共有してください。特定の実装方法は次のとおりです。
com.hava.filenotfoundextexをインポートします.util.Iterator; Import java.util.properties; import organ .poi.hssf.Usermodel.hssfcellStyle; Import org.apache .poi.hssf.Usermodel.hssfrichtextString; Import org.apache.hssf.Usermodel.hssfrow; Import port org .apache.poi.hssf.usermodel.hssfworkbook .apache.hssf.util.hssfcolor {//プロパティを保存するハッシュマップを作成する>(); public static void main([string] args){// readwritexlsproperties readwritexlsdemo = new readwritexlspropers(); config.properties "); // call method writeexcel()readritexlsdemo.writetoexcel(" test.xls ");} private void readproperties(string propertiesfilepath){//ファイルCTを作成するパスを作成するファイルCTを作成するためのパスを取得します。プロパティ//ファイルプロパティファイル=新しいファイル(PropertiesFilePath); (PropertiesFile); Properties Object // Properties key and fileInputStream Properties = new Properties() //上記のプロパティ上のメソッド//列挙タイプの列挙<オブジェクト> keysenum = properties.keys()で戻します。 。 propmap.put(propkey.tolowercase().trim()、propvalue.tologycase()。trim());} //ハッシュマップを印刷してfileinputStream system.out.println( "プロパティマップ... /n(" "ropmap); fisprop.close();} catch(filenotfoundexception e){e.printstacktrace();} catch(ioexception e){e.printstacktrace();}}} private voidoeee eaxcel(ing excelpath){//作成hssfringbookオブジェクトを使用したワークブックhssforkbook = new hssforkbook(); //ワークシートのメソッドを呼び出すことにより、hssfrow row.createrow((short)0); setfillforegroundcolor()およびsetfilltyle.setfillforegroundcolor(hssfcolor.gold.index)としてのhssfcellstyleを呼び出す前景と充填パターン上記で作成されたオブジェクトhssfcell1 = row.createcell(0);上記のスタイル。 havemap // keyset()メソッドを呼び出すことにより、setのポイント<strong> .keyset() iteratorの要素while(iterator.hasnext()){//最後のuserd行でワークシートから新しい行を作成 + 1 localfrow rowone.createrow(worldsheet。getlastropnum()+1); 0および1のrowne.createCell.CreateCell.CreateCell(1)で2つのセルが作成されます。 iterator.next();文字列=(key); {fileoutstream fosexcel = null; ); // fileoutputstream fosexcel.flush();
この記事がすべての人のJavaプログラムのデザインに役立つことが期待されています。