基于POI和easyexcel实现excel文件读写-多列表加下拉选项框( 三 )


填充模板代码
//设置下拉框模型String[] spinnerData1 = new String[]{"string", "number", "integer", "object", "array", "boolean"};String[] spinnerData2 = new String[]{"string", "number", "integer", "object", "array", "boolean"};SpinnerModel spinnerModel1 = new SpinnerModel();spinnerModel1.setSpinnerData(spinnerData1);spinnerModel1.setStartRowIndex(35);spinnerModel1.setEndRowIndex(35 + inputParameterList.size()-1);spinnerModel1.setStartColumnIndex(3);spinnerModel1.setEndColumnIndex(3);SpinnerModel spinnerModel2 = new SpinnerModel();spinnerModel2.setSpinnerData(spinnerData2);spinnerModel2.setStartRowIndex(35 + inputParameterList.size() + 1);spinnerModel2.setEndRowIndex(35 + inputParameterList.size() + 1 + outputParameterList.size()-1);spinnerModel2.setStartColumnIndex(3);spinnerModel2.setEndColumnIndex(3);List spinnerList = new ArrayList<>();spinnerList.add(spinnerModel1);spinnerList.add(spinnerModel2);//写入模板excelWriter = EasyExcel.write(newPath).excelType(ExcelTypeEnum.XLS).withTemplate(templatePath).registerWriteHandler(new CustomSpinnerHandler(spinnerList)).build();WriteSheet writeSheet = EasyExcel.writerSheet().build();//每写一行自动添加一行新空行FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();//写列表excelWriter.fill(new FillWrapper("a", inputParameterList), fillConfig, writeSheet);excelWriter.fill(new FillWrapper("b", outputParameterList), fillConfig, writeSheet);//写其他信息excelWriter.fill(baseServiceData, fillConfig, writeSheet);excelWriter.close();
需要注意的是如果模板中存在多个列表,需要加前缀区分
如果新模板中有下拉选项填充,则需要去掉告警的勾选
以上仅作为个人工作学习记录,如有不妥敬请指正 。