修正数据并校验,此方法在每次写入数据前都需要校验,因为用户可能修改参数而导致参数非法

@throws WriteExcelException 校验错误异常
545706
private void validateDataPerWrite() throws WriteExcelException {
        //修正数据,并校验
        if (CollectionUtils.isEmpty(this.properties)) {
            if (CollectionUtils.isEmpty(this.datas)) {
                //此种情况下被写入数据不能为空,因为默认会根据datas去自动获取需要被写入的属性
                throw new WriteExcelException("datas为空,请检查数据");
            }
            T data = this.datas.get(0);
            this.setProperties(data instanceof Map ? ((Map) data).keySet() : CommonUtils.toMap(data).keySet());
        }
        if (CollectionUtils.isNotEmpty(this.excludeProps)) {
            //若设置了排除元素,先将元素排除
            this.properties.removeAll(this.excludeProps);
        }
        if (CollectionUtils.isEmpty(this.properties)) {
            throw new WriteExcelException("properties为空!");
        }
        if (this.isWriteTitle && CollectionUtils.isEmpty(this.titles)) {
            this.setTitles(this.properties);
        }
        if (this.isWriteTitle && this.properties.size() != this.titles.size()) {
            throw new WriteExcelException("属性与标题列数不一致");
        }
        if (XLSX == this.excelType && this.properties.size() > XLSX_COLUMN_MOST) {
            throw new WriteExcelException(String.format("列数不得超过最大值%d", XLSX_COLUMN_MOST));
        }
        if (XLS == this.excelType && this.properties.size() > XLS_COLUMN_MOST) {
            throw new WriteExcelException(String.format("列数不得超过最大值%d", XLS_COLUMN_MOST));
        }
        if (this.defaultCellStyle == null) {
            this.defaultCellStyle = this.workbook.createCellStyle();
            this.defaultCellStyle.setFont(this.workbook.createFont());
            this.defaultCellStyle.setAlignment(HorizontalAlignment.CENTER);
            this.defaultCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        }
        if (this.isWriteTitle && this.defaultTitleCellStyle == null) {
            this.defaultTitleCellStyle = this.workbook.createCellStyle();
            Font font = this.workbook.createFont();
            font.setBold(true);
            font.setFontHeightInPoints((short) 16);
            this.defaultTitleCellStyle.setFont(font);
            this.defaultTitleCellStyle.setAlignment(HorizontalAlignment.CENTER);
            this.defaultTitleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        }
        if (this.handleCellValue != null) {
            this.map = new HashMap<>(2);
        }
    }
1198178
public function prev()
    {
        if ($this->position <= $this->startRow) {
            throw new PHPExcel_Exception("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})");
        }

        do {
            --$this->position;
        } while (($this->onlyExistingCells) &&
            (!$this->subject->cellExistsByColumnAndRow($this->columnIndex, $this->position)) &&
            ($this->position >= $this->startRow));
    }
930357
private void writeEnvelope(ByteWriter writer) throws IOException {

		if (envelope != null) {

			// Write x and y values
			writer.writeDouble(envelope.getMinX());
			writer.writeDouble(envelope.getMaxX());
			writer.writeDouble(envelope.getMinY());
			writer.writeDouble(envelope.getMaxY());

			// Write z values
			if (envelope.hasZ()) {
				writer.writeDouble(envelope.getMinZ());
				writer.writeDouble(envelope.getMaxZ());
			}

			// Write m values
			if (envelope.hasM()) {
				writer.writeDouble(envelope.getMinM());
				writer.writeDouble(envelope.getMaxM());
			}
		}
	}
161187
void writeSheet(Writer writer) throws WriterException {
        // create sheet
        this.sheet = workbook.createSheet(writer.sheetName());

        // setting styles
        CellStyle headerStyle = Constant.defaultHeaderStyle(workbook);
        CellStyle columnStyle = Constant.defaultColumnStyle(workbook);
        CellStyle titleStyle  = Constant.defaultTitleStyle(workbook);
        if (null != writer.titleStyle()) {
            titleStyle = writer.titleStyle().accept(workbook, titleStyle);
        }
        if (null != writer.headerStyle()) {
            headerStyle = writer.headerStyle().accept(workbook, headerStyle);
        }
        if (null != writer.cellStyle()) {
            columnStyle = writer.cellStyle().accept(workbook, columnStyle);
        }

        if (writer.isRaw()) {
            writer.sheetConsumer().accept(sheet);
        } else {
            // compute the Filed to be written
            Collection<?> rows   = writer.rows();
            Field[]       fields = rows.iterator().next().getClass().getDeclaredFields();

            this.fieldIndexes = new HashMap<>(fields.length);
            this.columns = new ArrayList<>();

            for (Field field : fields) {
                ExcelColumn column = field.getAnnotation(ExcelColumn.class);
                if (null != column) {
                    field.setAccessible(true);
                    fieldIndexes.put(column.index(), field);
                    columns.add(column);
                }
            }

            int colRowIndex = 0;
            // write title
            String title = writer.headerTitle();
            if (StringUtil.isNotEmpty(title)) {
                Integer maxColIndex = columns.stream()
                        .map(ExcelColumn::index)
                        .max(comparingInt(Integer::intValue))
                        .get();

                this.writeHeader(titleStyle, sheet, title, maxColIndex);
                colRowIndex = 1;
            }

            this.rowNum = writer.startRow();
            if (this.rowNum == 0) {
                this.rowNum = colRowIndex + 1;
            }

            try {
                // write column header
                this.writeColumnNames(colRowIndex, headerStyle);

                // write rows
                for (Object row : rows) {
                    this.writeRow(row, columnStyle);
                }
            } catch (Exception e) {
                log.error("write row fail", e);
            }
        }

        // write to OutputStream
        try (OutputStream os = outputStream) {
            workbook.write(os);
        } catch (Exception e) {
            throw new WriterException("workbook write to OutputStream error", e);
        }
    }
205562
public void writeToExcel(List<? extends Object> datas, boolean hasTitle, String path,
                             int inMemory, boolean transverse) throws IOException {
        writeToExcel(datas, hasTitle, new FileOutputStream(path), inMemory, transverse);
    }
1248305
private function writeFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
    {
        // Check if this is a pattern type or gradient type
        if ($pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR ||
            $pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_PATH) {
            // Gradient fill
            $this->writeGradientFill($objWriter, $pFill);
        } elseif ($pFill->getFillType() !== null) {
            // Pattern fill
            $this->writePatternFill($objWriter, $pFill);
        }
    }
354316
public static <T> void writeWorkBook(File file, int excelType, List<T> beans) throws WriteExcelException {
        WriteExcelUtils.writeWorkBook(file, excelType, beans, null);
    }
962697
@Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeByte(type);
        switch (type) {
            case BIG_MONEY: {
                BigMoney obj = (BigMoney) object;
                writeBigMoney(out, obj);
                return;
            }
            case MONEY: {
                Money obj = (Money) object;
                writeBigMoney(out, obj.toBigMoney());
                return;
            }
            case CURRENCY_UNIT: {
                CurrencyUnit obj = (CurrencyUnit) object;
                writeCurrency(out, obj);
                return;
            }
        }
        throw new InvalidClassException("Joda-Money bug: Serialization broken");
    }
209948
private void writeRow(String... columns) throws IOException {
        StringBuilder html = new StringBuilder();
        html.append("<tr>");
        for(String data : columns) {
            html.append("<td>").append(data).append("</td>");
        }
        html.append("</tr>\n");
        writer.write(html.toString());
    }
832963
private boolean setCellValue(Cell cell, Object value, String property) throws WriteExcelException {
        boolean isBlankCell = false;
        if (value == null) {
            cell.setCellValue("");
            isBlankCell = true;
        } else if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Integer) {
            cell.setCellValue((Integer) value);
        } else if (value instanceof Date || value instanceof Calendar) {
            if (MapUtils.isNotEmpty(this.dateFormatMapping) && this.dateFormatMapping.containsKey(property)) {
                //证明设置了该列名到日期格式的映射,日期格式采用映射格式
                this.dateFormatTemp.applyPattern(this.dateFormatMapping.get(property));
                cell.setCellValue(
                        this.dateFormatTemp.format(value instanceof Date ? value : ((Calendar) value).getTime()));
            } else {
                //采用默认的日期格式
                cell.setCellValue(
                        this.defaultDateFormat.format(value instanceof Date ? value : ((Calendar) value).getTime()));
            }
        } else if (value instanceof Boolean) {
            if (MapUtils.isNotEmpty(this.booleanMapping) && this.booleanMapping.containsKey(property)) {
                //证明设置了该列名到boolean值的映射,写入cell的值采用映射值
                Object valueMapping = this.booleanMapping.get(property).get((boolean) value ? TRUE : FALSE);
                if (valueMapping instanceof Boolean) {
                    throw new WriteExcelException(String.format("[%s]属性的boolean映射值类型不能再是boolean", property));
                }
                isBlankCell = this.setCellValue(cell, valueMapping, property);
            } else {
                cell.setCellValue((Boolean) value);
            }
        } else if (value instanceof Float) {
            cell.setCellValue((Float) value);
        } else if (value instanceof Double) {
            cell.setCellValue((Double) value);
        } else if (value instanceof Byte) {
            cell.setCellValue((Byte) value);
        } else if (value instanceof Short) {
            cell.setCellValue((Short) value);
        } else if (value instanceof Long) {
            cell.setCellValue((Long) value);
        } else if (value instanceof Character) {
            cell.setCellValue(((Character) value).toString());
        } else {
            cell.setCellValue(value.toString());
        }
        return isBlankCell;
    }
601350
@Override
    public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
	try {
	    out.writeObject(new HashMap(this));
	}
	catch (NotSerializableException nse) {
	    NotSerializableException tmp = new NotSerializableException(nse.getMessage() + ":" + entries());
	    tmp.initCause(nse);
	    throw tmp;
	}
    }
9377
protected function output()
    {
        ob_start();

        $writer = PHPExcel_IOFactory::createWriter($this->PhpExcel, 'Excel2007');

        if (!isset($writer)) {
            throw new Exception('Excel writer not found');
        }

        $writer->setPreCalculateFormulas(false);
        $writer->setIncludeCharts(true);
        $writer->save('php://output');

        $output = ob_get_clean();

        return $output;
    }
51217
private boolean writePerRow(Row row, Map<String, Object> data, T originData) throws WriteExcelException {
        boolean isNotBlankRow = false;
        //标识当前写入的列
        int currenCol = -1;
        for (String property : this.properties) {
            currenCol++;
            if (data.containsKey(property)) {
                Cell cell = row.createCell(currenCol);
                if (this.handleCellValue != null) {
                    this.map.clear();
                    this.handleCellValue.callback(property, data.get(property), originData, this);
                }
                CellStyle cellStyleTemp = this.defaultCellStyle;
                Object value = data.get(property);
                if (MapUtils.isNotEmpty(this.cellStyleMapping) && this.cellStyleMapping.containsKey(property)) {
                    cellStyleTemp = this.cellStyleMapping.get(property);
                }
                if (MapUtils.isNotEmpty(this.map)) {
                    if (this.map.get(CELL_STYLE) instanceof CellStyle) {
                        cellStyleTemp = (CellStyle) this.map.get(CELL_STYLE);
                    }
                    value = this.map.getOrDefault(CELL_VALUE, value);
                }
                cell.setCellStyle(cellStyleTemp);
                if (!this.setCellValue(cell, value, property)) {
                    isNotBlankRow = true;
                }
            }
        }
        return isNotBlankRow;
    }
1010753
public void writeToExcel(List<? extends Object> datas, boolean hasTitle,
                             String path) throws IOException {
        writeToExcel(datas, hasTitle, path, false);
    }
904017
private Writer doWrite(Writer writer, int indentFactor, int indent) throws IOException {
		writer.write(CharUtil.DELIM_START);
		boolean isFirst = true;
		final boolean isIgnoreNullValue = this.config.isIgnoreNullValue();
		final int newIndent = indent + indentFactor;
		for (Entry<String, Object> entry : this.entrySet()) {
			if (ObjectUtil.isNull(entry.getKey()) || (ObjectUtil.isNull(entry.getValue()) && isIgnoreNullValue)) {
				continue;
			}

			if (isFirst) {
				isFirst = false;
			} else {
				// 键值对分隔
				writer.write(CharUtil.COMMA);
			}
			// 换行缩进
			if (indentFactor > 0) {
				writer.write(CharUtil.LF);
			}

			InternalJSONUtil.indent(writer, newIndent);
			writer.write(JSONUtil.quote(entry.getKey().toString()));
			writer.write(CharUtil.COLON);
			if (indentFactor > 0) {
				// 冒号后的空格
				writer.write(CharUtil.SPACE);
			}
			InternalJSONUtil.writeValue(writer, entry.getValue(), indentFactor, newIndent, this.config);
		}

		// 结尾符
		if (indentFactor > 0) {
			writer.write(CharUtil.LF);
		}
		InternalJSONUtil.indent(writer, indent);
		writer.write(CharUtil.DELIM_END);
		return writer;
	}
764893
void write(CallInfo callInfo, SQLException e) {
    Element rootNode = root(callInfo);
    Element exNode = createNode(rootNode, DATABASE_EXCEPTION_TAG);
    StringWriter sw = new StringWriter();
    sw.append('\n');
    e.printStackTrace(new PrintWriter(sw));
    exNode.appendChild(xmlDoc.createCDATASection(sw.toString()));
    flush(rootNode);
  }
865968
public void noTemplateSheet2Excel(List<NoTemplateSheetWrapper> sheets, OutputStream os)
            throws Excel4JException, IOException {

        try (Workbook workbook = exportExcelNoTemplateHandler(sheets, true)) {
            workbook.write(os);
        }
    }