Ssio 是一个简单的电子表格I/O。
基本功能
把Javabeans存入Excel/CSV, 或者从Excel/CSV中解析出Javabean
特性
通过Annotation把JavabeanProperty映射到列支持日期格式支持复杂类型支持扩展以支持Excel/CSV之外的文件类型其它代码示例
BeandefinitionpublicclassPlayer{@SsColumn(index=0,name="Id")privatelongid;@SsColumn(index=1)//thecolumnnamewillbedecidedas"BirthCountry"privateStringbirthCountry;@SsColumn(index=2,typeHandler=FullNameTypeHandler.class)//complexproptypeprivateFullNamefullName;@SsColumn(index=3)//Theenum'sname()willbesaved.Otherwise,useatypeHandlerprivateSportTypesportType;@SsColumn(index=4,format="yyyy/MM/dd")//dateformatprivateLocalDatebirthDate;@SsColumn(index=5,typeHandler=TimestampAsMillisHandler.class)//ifyouprefersavingtimestampasnumberprivateLocalDateTimecreatedWhen;...}SaveSaveParam<Player>saveParam=//Excel-likefile.ForCSV,use"newCsvSaveParamBuilder()"newOfficeSaveParamBuilder<Player>().setBeanClass(Player.class).setBeans(players).setOutputTarget(outputStream).build();//GototheSsioManagerFactory.javatoseeIoCoptionsSsioManagerssioManager=SsioManagerFactory.newInstance();SaveResultsaveResult=ssioManager.save(saveParam);//saveResult.getDatumErrors()Parse//Excel-likefile.ForCSV,use"newCsvParseParamBuilder()"ParseParam<Player>parseParam=newOfficeParseParamBuilder().setBeanClass(Player.class).setSpreadsheetInput(inputStream).build();ParseResult<Player>parseResult=ssioManager.parse(parseParam);List<Player>parsedPlayers=parseResult.getBeans();//parseResult.getCellErrors();
评论