| | |
| | | */
|
| | | public List<T> importExcel(InputStream is)
|
| | | {
|
| | | return importExcel(is, 0);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对excel表单默认第一个索引名转换成list
|
| | | * |
| | | * @param is 输入流
|
| | | * @param titleNum 标题占用行数
|
| | | * @return 转换后集合
|
| | | */
|
| | | public List<T> importExcel(InputStream is, int titleNum)
|
| | | {
|
| | | List<T> list = null;
|
| | | try
|
| | | {
|
| | | list = importExcel(is, 0);
|
| | | list = importExcel(StringUtils.EMPTY, is, titleNum);
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | |
| | | IOUtils.closeQuietly(is);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 对excel表单默认第一个索引名转换成list
|
| | | * |
| | | * @param is 输入流
|
| | | * @param titleNum 标题占用行数
|
| | | * @return 转换后集合
|
| | | */
|
| | | public List<T> importExcel(InputStream is, int titleNum) throws Exception
|
| | | {
|
| | | return importExcel(StringUtils.EMPTY, is, titleNum);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel)
|
| | | {
|
| | | String key = StringUtils.format("data_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType());
|
| | | String key = StringUtils.format("data_{}_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType(), excel.wrapText());
|
| | | if (!styles.containsKey(key))
|
| | | {
|
| | | CellStyle style = wb.createCellStyle();
|
| | |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
| | | style.setFillForegroundColor(excel.backgroundColor().getIndex());
|
| | | style.setWrapText(excel.wrapText());
|
| | | Font dataFont = wb.createFont();
|
| | | dataFont.setFontName("Arial");
|
| | | dataFont.setFontHeightInPoints((short) 10);
|
| | |
| | | if (isSubList())
|
| | | {
|
| | | // 填充默认样式,防止合并单元格样式失效
|
| | | sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType())));
|
| | | sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
| | | if (attr.needMerge())
|
| | | {
|
| | | sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
|
| | |
| | | sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
|
| | | }
|
| | | }
|
| | | cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType())));
|
| | | cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
| | |
|
| | | // 用于读取对象中的属性
|
| | | Object value = getTargetValue(vo, field, attr);
|