网站排名怎么做 site,建设网站如何弄好几张网站背景,阿里巴巴国际站工作怎么样,苏州平面设计公司前十名个人说明#xff1a;为了简单实现导出数据较少的EXCEL(根据自定义书签模板)一、替换Excel表格标签方法/*** 替换Excel模板文件内容* param map* 需要替换的标签建筑队形式* param intPath* Excel模板文件路径* param outPath* Excel生成文件路径*/public static boolean repla…个人说明为了简单实现导出数据较少的EXCEL(根据自定义书签模板)一、替换Excel表格标签方法/*** 替换Excel模板文件内容* param map* 需要替换的标签建筑队形式* param intPath* Excel模板文件路径* param outPath* Excel生成文件路径*/public static boolean replaceSheetsModel(Map map, String intPath, String outPath) {boolean flag true;try {FileInputStream fs new FileInputStream(intPath);//EXCEL xlsx格式与xls格式用的类是不同的xlsx用的是XSSFWorkbookXSSFWorkbook workbook new XSSFWorkbook(fs);XSSFWorkbook wb (XSSFWorkbook) workbook;XSSFSheet sheet;//由于个人使用是多sheet故获取excel对象后进行sheet遍历分别对每个sheet里面的标签进行替换for (int j 0; j wb.getNumberOfSheets(); j) {sheet workbook.getSheetAt(j);Iterator rows sheet.rowIterator();while (rows.hasNext()) {XSSFRow row (XSSFRow) rows.next();if (row ! null) {int num row.getLastCellNum();for (int i 0; i num; i) {XSSFCell cell row.getCell(i);if (cell ! null) {cell.setCellType(XSSFCell.CELL_TYPE_STRING);}if (cell null || cell.getStringCellValue() null) {continue;}String value cell.getStringCellValue();if (!.equals(value)) {Set keySet item.keySet();Iterator it keySet.iterator();while (it.hasNext()) {String text it.next();if (value.equalsIgnoreCase(text)) {cell.setCellValue((String) item.get(text));break;}}} else {cell.setCellValue();}}}}}// 输出文件FileOutputStream fileOut new FileOutputStream(outPath);wb.write(fileOut);fileOut.close();} catch (Exception e) {flag false;e.printStackTrace();}return flag;}二、借助main方法进行测试public static void main(String[] args) {Map map new HashMap();map.put(aa, sheet1);map.put(bb, sheet2);map.put(cc, sheet3);map.put(dd, sheet4);// test.xlsx为Excel模板文件,sheets.xlsx为程序生成的新文件replaceSheetsModel(item, f:\test.xlsx, f:\\sheets.xlsx);}三、工具包说明(JAVAPOI)1.头部核心import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;2.工具包名称以及版本poi-ooxml 3.16如有疑问若不嫌弃可私信我也可一起探讨POI 操作EXCEL表格相互成长