将指定WorkBook里的记录封装成指定类型放入List中返回

@param clazz    指定封装类型
@param workbook
@return 无结果返回空List
@throws ReadExcelException
977560
public static <T> List<T> handleWorkBookToBeans(Class<T> clazz, Workbook workbook) throws ReadExcelException {
        List<Map<String, Object>> listMap = ReadExcelUtils.handleWorkBookToMapList(workbook);
        List<T> beans = new ArrayList<T>();
        for (Map<String, Object> map : listMap) {
            T bean = CommonUtils.toBean(map, clazz);
            if (bean != null) {
                beans.add(bean);
            }
        }

        return beans;
    }
66468
public static List<StartContainerConfig> getContainers(Class clazz) {
      if (!cacheSCC.containsKey(clazz)) {
         cacheSCC.put(clazz, new ArrayList<>(1));
         ContainerStart cs = (ContainerStart) clazz.getAnnotation(ContainerStart.class);
         if (cs != null) {
            cacheSCC.get(clazz).add(fromContainerStart(cs));
         }
         Containers c = (Containers) clazz.getAnnotation(com.vectorprint.report.itext.annotations.Containers.class);
         if (c != null) {
            for (ContainerStart s : c.containers()) {
               cacheSCC.get(clazz).add(fromContainerStart(s));
            }
         }
      }
      return cacheSCC.get(clazz);
   }
313426
public static <T> Workbook writeWorkBook(Workbook workbook, List<T> beans) {
        return WriteExcelUtils.writeWorkBook(workbook, beans, null);
    }
330846
public <T> boolean write(List<T> list, Class<T> clazz) {
		
		List<Object[]> rows = ExcelBeanHelper.beanToExcelValueArrays(list, clazz);
		try {
			Sheet sheet = workbook.getSheetAt(0);
			for (int i = 2; i < rows.size(); i++) {
				Row excelRow = sheet.getRow(i);
				Object[] vals = rows.get(i);
				for (int j = 0; j < vals.length; j++) {
					Cell cell = excelRow.getCell(j);
					cell.setCellValue(vals[j] == null ? "" : vals[j].toString());
				}
			}
			workbook.write(outputStream);
			return true;
		} catch (IOException e) {
			LOG.error("流异常", e);
		} catch (Exception e) {
			LOG.error("其他异常", e);
		} 
		return false;
	}
949528
public static boolean list2Xls(ExcelConfig config, List<?> list, OutputStream outputStream) throws Exception {
        try {
            String[] header = config.getHeaders();
            String[] names = config.getNames();
            String[] values;
            WritableWorkbook wb = Workbook.createWorkbook(outputStream);
            String sheetName = (config.getSheet() != null && !config.getSheet().equals("")) ? config.getSheet() : ("sheet" + config.getSheetNum());
            WritableSheet sheet = wb.createSheet(sheetName, 0);

            int row = 0;
            int column = 0;
            int rowadd = 0;
            //写入标题
            if (config.getHeader()) {
                for (column = 0; column < header.length; column++) {
                    sheet.addCell(new Label(column, row + rowadd, header[column]));
                    if (config.getColumn(column).getWidth() != null) {
                        sheet.setColumnView(column, config.getColumn(column).getWidth() / 7);
                    }
                }
                rowadd++;
            }
            //写入内容//行
            for (row = 0; row < list.size(); row++) {
                Object rowData = list.get(row);
                values = getObjValues(rowData, names);
                //列
                for (column = 0; column < values.length; column++) {
                    sheet.addCell(new Label(column, row + rowadd, values[column]));
                }
            }
            wb.write();
            wb.close();
        } catch (Exception e1) {
            return false;
        }
        return true;
    }
99084
private static Map<String, PictureData> getPicMapXlsx(XSSFWorkbook workbook, int sheetIndex) {
		final Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
		final XSSFSheet sheet = workbook.getSheetAt(sheetIndex);
		XSSFDrawing drawing;
		for (POIXMLDocumentPart dr : sheet.getRelations()) {
			if (dr instanceof XSSFDrawing) {
				drawing = (XSSFDrawing) dr;
				final List<XSSFShape> shapes = drawing.getShapes();
				XSSFPicture pic;
				CTMarker ctMarker;
				for (XSSFShape shape : shapes) {
					pic = (XSSFPicture) shape;
					ctMarker = pic.getPreferredSize().getFrom();
					sheetIndexPicMap.put(StrUtil.format("{}_{}", ctMarker.getRow(), ctMarker.getCol()), pic.getPictureData());
				}
			}
		}
		return sheetIndexPicMap;
	}
693334
private void initWorkbook() throws Docx4JException
    {
        if(pkg == null)
            return;

        wbp = pkg.getWorkbookPart();
        sheets = ((org.xlsx4j.sml.Workbook)wbp.getJaxbElement()).getSheets().getSheet();
        wbrp = wbp.getRelationshipsPart();
        if(wbrp == null)
        {
            wbrp = new RelationshipsPart();
            wbrp.setPartName(new PartName("/xl/_rels/workbook.xml.rels"));

            //wbrp = new RelationshipsPart(new PartName("/xl/_rels/workbook.xml.rels"));
            wbp.addTargetPart(wbrp);
        }

        prp = pkg.getRelationshipsPart();
        if(prp == null)
        {
            prp = new RelationshipsPart();
            pkg.addTargetPart(prp);
        }

        PartName ssPart = new PartName("/xl/sharedStrings.xml");
        sharedStrings = (SharedStrings)pkg.getParts().get(ssPart);
        if(sharedStrings == null)
        {
            sharedStrings = new SharedStrings(ssPart);
            sharedStrings.setJaxbElement(new CTSst());
            wbp.addTargetPart(sharedStrings);
        }
        strings = sharedStrings.getJaxbElement();

        PartName stylesPart = new PartName("/xl/styles.xml");
        styles = (Styles)pkg.getParts().get(stylesPart);
        if(styles == null)
        {
            styles = new Styles(stylesPart);
            CTStylesheet styleSheet = new CTStylesheet();
            styles.setJaxbElement(styleSheet);
            wbp.addTargetPart(styles);
        }
        stylesheet = styles.getJaxbElement();

        fonts = stylesheet.getFonts();
        if(fonts == null)
        {
            fonts = new CTFonts();
            stylesheet.setFonts(fonts);
        }

        cellXfs = stylesheet.getCellXfs();
        if(cellXfs == null)
        {
            cellXfs = new CTCellXfs();
            stylesheet.setCellXfs(cellXfs);
        }

        cellStyles = stylesheet.getCellStyles();
        if(cellStyles == null)
        {
            cellStyles = new CTCellStyles();
            stylesheet.setCellStyles(cellStyles);
        }

        cellStyleXfs = stylesheet.getCellStyleXfs();
        if(cellStyleXfs == null)
        {
            cellStyleXfs = new CTCellStyleXfs();
            stylesheet.setCellStyleXfs(cellStyleXfs);
        }

        borders = stylesheet.getBorders();
        if(borders == null)
        {
            borders = new CTBorders();
            stylesheet.setBorders(borders);
        }

        fills = stylesheet.getFills();
        if(fills == null)
        {
            fills = new CTFills();
            stylesheet.setFills(fills);
        }

        if(sheets != null) 
        {
            for(int i = 0; i < sheets.size(); i++)
            {
                Sheet sheet = (Sheet)sheets.get(i);
                WorksheetPart wsp = (WorksheetPart)wbrp.getPart(sheet.getId());
                if(wsp != null)
                    worksheets.put(sheet.getName(), new XlsxWorksheet(this, wsp));
            }
        }

        //printFontInfo();
    }
1080970
public static Field getJoinLeftTable(Class<?> clazz) {
		if(clazz == null) {
			throw new NoJoinTableMemberException("clazz is null");
		}
		List<Field> result = _getAnnotationColumns(clazz, JoinLeftTable.class);
		if(result == null || result.isEmpty()) {
			throw new NoJoinTableMemberException("class " + clazz.getName()
			    + " does not have @JoinLeftTable field");
		}
		return result.get(0);
	}
256118
public Workbook writeToExcel(List<? extends Object> datas, boolean hasTitle, Workbook workbook,
                                 boolean transverse) {
        if (CollectionUtil.safeIsEmpty(datas)) {
            log.warn("给定数据集合为空");
            return workbook;
        }
        datas = datas.parallelStream().filter(data -> data != null).collect(Collectors.toList());
        if (datas.isEmpty()) {
            log.warn("给定数据集合里的数据全是空");
            return workbook;
        }
        //获取所有字段（包括父类的）
        Field[] fields = ReflectUtil.getAllFields(datas.get(0).getClass());

        log.info("获取可写入excel的字段");
        List<Field> writeFields = new ArrayList<>();
        for (Field field : fields) {
            String name = field.getName();
            log.debug("检查字段[{}]是否可以写入", name);
            Class<?> type = field.getType();

            List<ExcelDataWriter<?>> data = writers.values().stream()
                .filter(excelData -> excelData.writeable(type)).collect(Collectors.toList());
            if (data.isEmpty()) {
                log.info("字段[{}]不能写入", name);
            } else {
                log.info("字段[{}]可以写入excel");
                ExcelColumn column = field.getAnnotation(ExcelColumn.class);

                if (column == null || !column.ignore()) {
                    writeFields.add(field);
                }
            }
        }
        log.debug("可写入excel的字段集合为：[{}]", writeFields);
        log.debug("对可写入excel的字段集合排序");

        Collections.sort(writeFields, COMPARATOR);

        log.debug("可写入excel的字段集合排序完毕，构建标题列表");

        List<Writer<?>> titles = null;
        if (hasTitle) {
            log.info("当前需要标题列表，构建...");
            titles = new ArrayList<>(writeFields.size());
            for (int i = 0; i < writeFields.size(); i++) {
                Field field = writeFields.get(i);
                ExcelColumn column = field.getAnnotation(ExcelColumn.class);
                if (column == null || StringUtils.isEmpty(column.value())) {
                    titles.add(build(field.getName()));
                } else {
                    titles.add(build(column.value()));
                }
            }
        }

        log.debug("构建单元格数据");
        List<List<Writer<?>>> writeDatas = new ArrayList<>(datas.size());
        for (int i = 0; i < datas.size(); i++) {
            Object dataValue = datas.get(i);
            //构建一行数据
            List<Writer<?>> columnDatas = new ArrayList<>(writeFields.size());
            //加入
            writeDatas.add(columnDatas);
            for (int j = 0; j < writeFields.size(); j++) {
                Field field = writeFields.get(j);
                try {
                    log.debug("获取[{}]中字段[{}]的值", dataValue, field.getName());
                    Object value = field.get(dataValue);
                    columnDatas.add(build(value));
                } catch (IllegalAccessException e) {
                    log.warn("[{}]中字段[{}]不能读取", dataValue, field.getName(), e);
                    columnDatas.add(null);
                }
            }
        }

        log.debug("要写入的数据为：[{}]", writeDatas);
        log.info("准备写入数据");
        writeToExcel(titles, writeDatas, hasTitle, workbook, transverse);
        log.info("标题列表为：[{}]", titles);
        return workbook;
    }
147557
public static boolean list2Xls(ExcelConfig config, List<?> list, String filePath, String fileName) throws Exception {
        return XlsUtil.list2Xls(config, list, filePath, fileName);
    }
497887
public static <T> Workbook writeWorkBook(Workbook workbook, int count, List<T> beans, List<String> properties,
                                             List<String> titles, String dateFormat) {
        return WriteExcelUtils.writeWorkBook(workbook, 0, count, beans, properties, titles, dateFormat);
    }
895706
public static Field[] getFields (Class<?> clazz)
    {
        ArrayList<Field> list = new ArrayList<Field>();
        getFields(clazz, list);
        return list.toArray(new Field[list.size()]);
    }
923607
public List<List<String>> readExcel2List(String excelPath, int offsetLine)
            throws IOException, InvalidFormatException {

        try (Workbook workbook = WorkbookFactory.create(new FileInputStream(new File(excelPath)))) {
            return readExcel2ObjectsHandler(workbook, offsetLine, Integer.MAX_VALUE, 0);
        }
    }
1340092
public <T> boolean write(List<T> list, Class<T> clazz) {
		
		ExcelMeta excelMeta = ExcelBeanHelper.getExcelMeta(clazz);
		try {
			Sheet sheet = workbook.createSheet(this.sheetName);
			sheet.setDefaultColumnWidth(15); 
			CellStyle titleStyle = workbook.createCellStyle(); 
			titleStyle.setAlignment(HorizontalAlignment.CENTER);
			titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
			titleStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
			titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
			titleStyle.setBorderBottom(BorderStyle.THIN); //下边框
			titleStyle.setBorderLeft(BorderStyle.THIN);
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 13);
			titleStyle.setFont(font);
			//列值类型
			Class<?>[] cellValueTypes = new Class<?>[excelMeta.getTitleColumnNum()];
			//写标题
			for (int i = 1; i <= excelMeta.getTitleRowNum(); i++) {
				Row excelRow = sheet.createRow(i - 1);
				for (int j = 1; j <= excelMeta.getTitleColumnNum(); j++) {
					TitleMeta titleMeta = excelMeta.getTitleMeta(i, j);
					Cell cell = excelRow.createCell(j - 1);
					cell.setCellValue(titleMeta == null ? "" : titleMeta.getTitle());
					cell.setCellStyle(titleStyle);
					cellValueTypes[j-1] = titleMeta.getValueType();
				}
			}
			//合并表头
            //sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 8));
			//sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
			mergeColumns(sheet,titleStyle);
			mergeRows(sheet,titleStyle,excelMeta);
			
			// 行数
			int rowsCount = sheet.getPhysicalNumberOfRows();
			//冻结表头
			//sheet.createFreezePane(0, rowsCount - 1);
			
			// 写入内容
			List<Object[]> rows = ExcelBeanHelper.beanToExcelValueArrays(list, clazz);
	        // 列数
	        //int colsCount = sheet.getRow(0).getPhysicalNumberOfCells();
			for (int i = 0; i < rows.size(); i++) {
				Row excelRow = sheet.createRow(i + rowsCount);
				
				Object[] vals = rows.get(i);
				for (int j = 0; j < vals.length; j++) {
					Cell cell = excelRow.createCell(j);
					if(cellValueTypes[j] == int.class || cellValueTypes[j] == Integer.class){
					    cell.setCellValue(vals[j] == null ? 0f : Integer.parseInt(vals[j].toString()));
					}else if(cellValueTypes[j] == float.class || cellValueTypes[j] == Float.class 
							|| cellValueTypes[j] == double.class || cellValueTypes[j] == Double.class
							|| cellValueTypes[j] == BigDecimal.class){
					    cell.setCellValue(vals[j] == null ? 0d : Double.parseDouble(vals[j].toString()));
					}else{
						cell.setCellValue(vals[j] == null ? "" : vals[j].toString());
					}
				}
			}
			workbook.write(outputStream);
			return true;
		} catch (IOException e) {
			LOG.error("流异常", e);
		} catch (Exception e) {
			LOG.error("其他异常", e);
		} finally {
		} 
		return false;
	}
557040
@Override
    public XlsxWorksheet getSheet(int i)
    {
        XlsxWorksheet ret = null;
        if(sheets != null)
        {
            Sheet sheet = (Sheet)sheets.get(i);
            if(sheet != null)
                ret = getSheet(sheet.getName());
        }
        return ret;
    }
679914
List<Field> getFields(Class<?> clazz) {
        List<Field> result = new ArrayList<>();
        Set<String> fieldNames = new HashSet<>();
        Class<?> searchType = clazz;
        while (!Object.class.equals(searchType) && searchType != null) {
            Field[] fields = searchType.getDeclaredFields();
            for (Field field : fields) {
                if (!fieldNames.contains(field.getName())) {
                    fieldNames.add(field.getName());
                    makeAccessible(field);
                    result.add(field);
                }
            }
            searchType = searchType.getSuperclass();
        }
        return result;
    }
468719
public Reader<T> sheet(String sheetName) {
        if (StringUtil.isEmpty(sheetName)) {
            throw new IllegalArgumentException("sheet cannot be empty");
        }
        this.sheetName = sheetName;
        return this;
    }