根据JavaBean，在模板页基础上生成Excel.
330303
@SuppressWarnings("unchecked")
    public Workbook create(Object bean) {
        optionsSheet = sheet.getWorkbook().getSheet("Options");

        for (val field : bean.getClass().getDeclaredFields()) {
            if (Fields.shouldIgnored(field, ExcelColIgnore.class)) continue;
            if (field.getName().endsWith("Tmpl")) continue;

            processExcelCellAnnotation(field, bean);
            processExcelRowsAnnotation(field, bean);
        }

        fixRowsHeight();
        PoiUtil.removeOtherSheets(sheet);


        val wb = sheet.getWorkbook();
        wb.setPrintArea(0, 0, PoiUtil.findMaxCol(sheet), 0, sheet.getLastRowNum());
        return wb;
    }
794106
public ExcelWriter writeRow(Map<?, ?> rowMap, boolean isWriteKeyAsHead) {
		Assert.isFalse(this.isClosed, "ExcelWriter has been closed!");
		if (MapUtil.isEmpty(rowMap)) {
			// 如果写出数据为null或空，跳过当前行
			return passCurrentRow();
		}

		final Map<?, ?> aliasMap = aliasMap(rowMap);

		if (isWriteKeyAsHead) {
			writeHeadRow(aliasMap.keySet());
		}
		writeRow(aliasMap.values());
		return this;
	}
923918
private Writer<?> build(Object data) {
        Optional<ExcelDataWriter<?>> dataBuilder = writers.values().parallelStream()
            .filter(excelData -> excelData.writeable(data)).limit(1).findFirst();

        ExcelDataWriter<?> writer = dataBuilder
            .orElseThrow(() -> new UtilsException("数据[" + data + "]没有对应的ExcelDataWriter"));
        return new Writer(writer, data);
    }
531590
public static Workbook createBook(File excelFile, String password) {
		try {
			return WorkbookFactory.create(excelFile, password);
		} catch (Exception e) {
			throw new POIException(e);
		}
	}
209515
@SneakyThrows @SuppressWarnings("unchecked")
    private void processExcelRowsAnnotation(Field field, Object bean) {
        val excelRows = field.getAnnotation(ExcelRows.class);
        if (excelRows == null) return;

        if (!Generic.of(field.getGenericType()).isRawType(List.class)) return;

        val templateCell = findTemplateCell(excelRows);
        if (templateCell == null) {
            log.warn("unable to locate template cell for field {}", field);
            return; // 找不到模板单元格，直接忽略字段处理。
        }

        val list = (List<Object>) Fields.invokeField(field, bean);
        val itemSize = PoiUtil.shiftRows(sheet, list, templateCell.getRowIndex());
        if (itemSize > 0) {
            writeRows(templateCell, list);
            mergeRows(excelRows, templateCell, itemSize);
            mergeCols(excelRows, templateCell, itemSize);
        }
    }
1154762
private String generateJavaCode() {
		final StringBuilder builder = new StringBuilder();
		final String newLine = "\n";

		// package information
		builder.append(StatusUpdateTemplate.class.getPackage().toString());
		builder.append(".templates");
		builder.append(";");
		builder.append(newLine);
		builder.append(newLine);

		// imports
		builder.append("import java.util.Map;");
		builder.append(newLine);
		builder.append(newLine);
		builder.append("import ");
		builder.append(StatusUpdate.class.getName());
		builder.append(";");
		builder.append(newLine);
		builder.append(newLine);

		// class
		builder.append("public class ");
		builder.append(this.name);
		builder.append(" extends StatusUpdate {");
		builder.append(newLine);
		builder.append(newLine);

		// type identifier
		builder.append("public static final String TYPE_IDENTIFIER = \"");
		builder.append(this.name);
		builder.append("\";");
		builder.append(newLine);
		builder.append(newLine);

		// template fields
		TemplateFieldInfo field;
		for (String fieldName : this.fields.keySet()) {
			field = this.fields.get(fieldName);

			builder.append("public ");
			builder.append(field.getType());
			builder.append(" ");
			builder.append(field.getName());
			builder.append(";");
			builder.append(newLine);
			builder.append(newLine);
		}

		// template files
		TemplateFileInfo file;
		for (String fileName : this.files.keySet()) {
			file = this.files.get(fileName);

			builder.append("public String ");
			builder.append(file.getName());
			builder.append(";");
			builder.append(newLine);
			builder.append(newLine);
		}

		// constructor
		builder.append("public ");
		builder.append(this.name);
		builder.append("() {");
		builder.append(newLine);
		builder.append("super(TYPE_IDENTIFIER);");
		builder.append(newLine);
		builder.append("}");
		builder.append(newLine);
		builder.append(newLine);

		// JSON parsing
		builder.append("@Override");
		builder.append(newLine);
		builder.append("protected Map<String, Object> toObjectJSON() {");
		builder.append(newLine);
		builder.append("final Map<String, Object> objectJSON = super.toObjectJSON();");
		builder.append(newLine);
		for (String fieldName : this.fields.keySet()) {
			builder.append("objectJSON.put(\"");
			builder.append(fieldName);
			builder.append("\", this.");
			builder.append(fieldName);
			builder.append(");");
			builder.append(newLine);
		}
		for (String fileName : this.files.keySet()) {
			builder.append("objectJSON.put(\"");
			builder.append(fileName);
			builder.append("\", this.");
			builder.append(fileName);
			builder.append(");");
			builder.append(newLine);
		}
		builder.append("return objectJSON;");
		builder.append(newLine);
		builder.append("}");
		builder.append(newLine);
		builder.append(newLine);
		builder.append("}");

		return builder.toString();
	}
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);
        }
    }
1013031
private static void createIf(MethodVisitor mv, Method method, Label next, Label start,
                                 String className, Class<?> parentClass) {
        // 标记分支开始位置
        mv.visitLabel(start);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        // 比较方法声明类
        stringEquals(mv, () -> mv.visitVarInsn(ALOAD, 1), convert(method.getDeclaringClass()), next,
            () -> {
                // 比较方法名
                stringEquals(mv, () -> mv.visitVarInsn(ALOAD, 2), method.getName(), next, () -> {
                    // 方法名一致再比较方法说明
                    stringEquals(mv, () -> mv.visitVarInsn(ALOAD, 3),
                        ByteCodeUtils.getMethodDesc(method), next, () -> {
                            // 方法说明也一致后执行方法
                            invokeMethod(mv, method, () -> {
                                // 调用代理对象对应的方法而不是本代理的方法
                                mv.visitVarInsn(ALOAD, 0);
                                mv.visitFieldInsn(GETFIELD, convert(className), TARGET_FIELD_NAME,
                                    getByteCodeType(parentClass));
                                // 获取参数数量，用于载入参数
                                int count = method.getParameterCount();
                                Class<?>[] types = method.getParameterTypes();

                                // 循环载入参数
                                for (int i = 0; i < count; i++) {
                                    mv.visitVarInsn(Opcodes.ALOAD, 4);
                                    // 这里注意，访问数组下标0-5和6-无穷是不一样的
                                    // 访问0-5对应的byte code：  aload | iconst_[0-5] | aaload
                                    // 访问下标大于5的byte code: aload | bipush [6-无穷] aaload
                                    if (i <= 5) {
                                        mv.visitInsn(ICONST_0 + i);
                                    } else {
                                        mv.visitIntInsn(BIPUSH, i);
                                    }
                                    mv.visitInsn(Opcodes.AALOAD);
                                    mv.visitTypeInsn(CHECKCAST, convert(types[i]));
                                }
                            });
                        });
                });
            });
    }
627624
void process() {
        fixImports();
        if (insertRegion != null) {
            data.ensureImport(BeanDefinition.class);
            if (properties.size() > 0) {
                data.ensureImport(PropertyDefinition.class);
            }
            removeOld();
            if (data.isRootClass() && data.isExtendsDirectBean()) {
                data.ensureImport(DirectBean.class);
            }
            generateMeta();
            generateSerializationVersionId();
            generatePropertyChangeSupportField();
            generateHashCodeField();
            generateFactory();
            generateImmutableBuilderMethod();
            generateArgBasedConstructor();
            generateBuilderBasedConstructor();
            generateMetaBean();
            generateGettersSetters();
            generateSeparator();
            generateImmutableToBuilder();
            generateClone();
            generateEquals();
            generateHashCode();
            generateToString();
            generateMetaClass();
            generateBuilderClass();
            resolveImports();
            resolveIndents();
        }
    }
1228962
private Optional<NumberFormat> createFormatter(final Optional<XlsNumberConverter> convertAnno) {
        
        if(!convertAnno.isPresent()) {
            return Optional.empty();
        }
        
        final Optional<String> javaPattern = getJavaPattern(convertAnno);
        final Locale locale = Utils.getLocale(convertAnno.get().locale());
        final DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
        final Optional<Currency> currency = convertAnno.get().currency().isEmpty() ? Optional.empty()
                : Optional.of(Currency.getInstance(convertAnno.get().currency()));
        
        if(!javaPattern.isPresent()) {
            if(!convertAnno.get().currency().isEmpty()) {
                // 通貨の場合
                DecimalFormat formatter = (DecimalFormat)NumberFormat.getCurrencyInstance(locale);
                formatter.setParseBigDecimal(true);
                formatter.setDecimalFormatSymbols(symbols);
                currency.ifPresent(c -> formatter.setCurrency(c));
                
                return Optional.of(formatter);
                
            } else {
                return Optional.empty();
            }
        }
        
        final DecimalFormat formatter = new DecimalFormat(javaPattern.get(), symbols);
        
        formatter.setRoundingMode(RoundingMode.HALF_UP);
        formatter.setParseBigDecimal(true);
        currency.ifPresent(c -> formatter.setCurrency(c));
        
        return Optional.of(formatter);
        
    }
247352
public String export() throws Exception {
    TransferFormat format = Enums.get(TransferFormat.class, Strings.capitalize(get("format", "Xls")))
        .getOrElse(TransferFormat.Xls);
    String fileName = get("fileName");
    String template = get("template");
    if (Strings.isEmpty(fileName)) fileName = "exportResult";
    // 配置导出上下文
    Context context = new Context();
    context.put("format", format);
    context.put("exportFile", fileName);
    context.put("template", template);
    String properties = get("properties");
    if (null != properties) {
      String[] props = Strings.split(properties, ",");
      List<String> keys = CollectUtils.newArrayList();
      List<String> titles = CollectUtils.newArrayList();
      for (String prop : props) {
        if (prop.contains(":")) {
          keys.add(Strings.substringBefore(prop, ":"));
          titles.add(getTextInternal(Strings.substringAfter(prop, ":")));
        } else {
          keys.add(prop);
          titles.add(getTextInternal(getShortName() + "." + prop));
        }
      }
      context.put(Context.KEYS, Strings.join(keys, ","));
      context.put(Context.TITLES, Strings.join(titles, ","));
    } else {
      context.put(Context.KEYS, get("keys"));
      context.put(Context.TITLES, get("titles"));
    }
    context.put(Context.EXTRACTOR, getPropertyExtractor());

    HttpServletResponse response = ServletActionContext.getResponse();
    Exporter exporter = buildExporter(format, context);
    configExporter(exporter, context);
    if (format.equals(TransferFormat.Xls)) {
      response.setContentType("application/vnd.ms-excel;charset=GBK");
    } else {
      response.setContentType("application/x-msdownload");
    }
    response.setHeader("Content-Disposition",
        "attachment;filename=" + RequestUtils.encodeAttachName(ServletActionContext.getRequest(),
            fileName + "." + Strings.uncapitalize(format.name())));
    // 进行输出
    exporter.setContext(context);
    exporter.transfer(new TransferResult());
    return null;
  }
1132466
private static void generateDotString(final Formula formula, final StringBuilder sb, final Map<Formula, Integer> ids) {
    switch (formula.type()) {
      case FALSE:
        sb.append(String.format("  false;%n"));
        break;
      case TRUE:
        sb.append(String.format("  true;%n"));
        break;
      case LITERAL:
        break;
      case PBC:
        final int id = ids.size();
        ids.put(formula, id);
        sb.append("  id").append(id).append(" [label=\"").append(formula.toString()).append(String.format("\"];%n"));
        for (final Formula operand : ((PBConstraint) formula).operands())
          sb.append("  id").append(id).append(" -> id").append(ids.get(operand)).append(String.format(";%n"));
        break;
      case NOT:
        generateNotDotString((Not) formula, sb, ids);
        break;
      case IMPL:
        generateBinaryDotString((BinaryOperator) formula, sb, ids, "⇒", true);
        break;
      case EQUIV:
        generateBinaryDotString((BinaryOperator) formula, sb, ids, "⇔", true);
        break;
      case AND:
        generateNaryDotString((NAryOperator) formula, sb, ids, "∧");
        break;
      case OR:
        generateNaryDotString((NAryOperator) formula, sb, ids, "∨");
        break;
      default:
        throw new IllegalArgumentException("Cannot write the formula type " + formula.type());
    }

  }

  private static void generateNotDotString(final Not not, final StringBuilder sb, final Map<Formula, Integer> ids) {
    int id;
    if (!ids.containsKey(not.operand()))
      generateDotString(not.operand(), sb, ids);
    id = ids.size();
    ids.put(not, id);
    sb.append("  id").append(id).append(String.format(" [label=\"¬\"];%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(not.operand())).append(String.format(";%n"));
  }

  private static void generateBinaryDotString(final BinaryOperator formula, final StringBuilder sb,
                                              final Map<Formula, Integer> ids, String op, boolean directions) {
    if (!ids.containsKey(formula.left()))
      generateDotString(formula.left(), sb, ids);
    if (!ids.containsKey(formula.right()))
      generateDotString(formula.right(), sb, ids);
    final int id = ids.size();
    ids.put(formula, id);
    sb.append("  id").append(id).append(" [label=\"").append(op).append(String.format("\"];%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(formula.left()));
    sb.append(directions ? String.format(" [label=\"l\"];%n") : String.format(";%n"));
    sb.append("  id").append(id).append(" -> id").append(ids.get(formula.right()));
    sb.append(directions ? String.format(" [label=\"r\"];%n") : String.format(";%n"));
  }

  private static void generateNaryDotString(final NAryOperator formula, final StringBuilder sb,
                                            final Map<Formula, Integer> ids, final String op) {
    for (final Formula operand : formula)
      if (!ids.containsKey(operand))
        generateDotString(operand, sb, ids);
    final int id = ids.size();
    ids.put(formula, id);
    sb.append("  id").append(id).append(" [label=\"").append(op).append(String.format("\"];%n"));
    for (final Formula operand : formula)
      sb.append("  id").append(id).append(" -> id").append(ids.get(operand)).append(String.format(";%n"));
  }
}
1138137
public function generateSheetData() {
		// PHPExcel object known?
		if (is_null($this->_phpExcel)) {
			throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
		}

		// Ensure that Spans have been calculated?
		if (!$this->_spansAreCalculated) {
			$this->_calculateSpans();
		}

		// Fetch sheets
		$sheets = array();
		if (is_null($this->_sheetIndex)) {
			$sheets = $this->_phpExcel->getAllSheets();
		} else {
			$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
		}

		// Construct HTML
		$html = '';

		// Loop all sheets
		$sheetId = 0;
		foreach ($sheets as $sheet) {
			// Write table header
			$html .= $this->_generateTableHeader($sheet);

			// Get worksheet dimension
			$dimension = explode(':', $sheet->calculateWorksheetDimension());
			$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
			$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
			$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
			$dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;

			// row min,max
			$rowMin = $dimension[0][1];
			$rowMax = $dimension[1][1];

			// calculate start of <tbody>, <thead>
			$tbodyStart = $rowMin;
			$theadStart = $theadEnd   = 0; // default: no <thead>	no </thead>
			if ($sheet->getPageSetup()->isRowsToRepeatAtTopSet()) {
				$rowsToRepeatAtTop = $sheet->getPageSetup()->getRowsToRepeatAtTop();

				// we can only support repeating rows that start at top row
				if ($rowsToRepeatAtTop[0] == 1) {
					$theadStart = $rowsToRepeatAtTop[0];
					$theadEnd   = $rowsToRepeatAtTop[1];
					$tbodyStart = $rowsToRepeatAtTop[1] + 1;
				}
			}

			// Loop through cells
			$row = $rowMin-1;
			while($row++ < $rowMax) {
				// <thead> ?
				if ($row == $theadStart) {
					$html .= '		<thead>' . PHP_EOL;
				}

				// <tbody> ?
				if ($row == $tbodyStart) {
					$html .= '		<tbody>' . PHP_EOL;
				}

				// Write row if there are HTML table cells in it
				if ( !isset($this->_isSpannedRow[$sheet->getParent()->getIndex($sheet)][$row]) ) {
					// Start a new rowData
					$rowData = array();
					// Loop through columns
					$column = $dimension[0][0] - 1;
					while($column++ < $dimension[1][0]) {
						// Cell exists?
						if ($sheet->cellExistsByColumnAndRow($column, $row)) {
							$rowData[$column] = $sheet->getCellByColumnAndRow($column, $row);
						} else {
							$rowData[$column] = '';
						}
					}
					$html .= $this->_generateRow($sheet, $rowData, $row - 1);
				}

				// </thead> ?
				if ($row == $theadEnd) {
					$html .= '		</thead>' . PHP_EOL;
				}
			}
			$html .= $this->_extendRowsForChartsAndImages($sheet, $row);

			// Close table body.
			$html .= '		</tbody>' . PHP_EOL;

			// Write table footer
			$html .= $this->_generateTableFooter();

			// Writing PDF?
			if ($this->_isPdf) {
				if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel->getSheetCount()) {
					$html .= '<div style="page-break-before:always" />';
				}
			}

			// Next sheet
			++$sheetId;
		}

		// Return
		return $html;
	}
354316
public static <T> void writeWorkBook(File file, int excelType, List<T> beans) throws WriteExcelException {
        WriteExcelUtils.writeWorkBook(file, excelType, beans, null);
    }
616755
function createFormContentRows() {
    var oThis = this,
        htmlStr = "";
    // 遍历生成所有行
    if (this.dataSourceObj.rows) {
        htmlStr += '<tbody role="rowgroup" id="' + this.options.id + '_form_content_tbody">';
        $.each(this.dataSourceObj.rows, function () {
            htmlStr += '<tr role="row"><td role="rowcell">';
            var value = this.value;
            $.each(oThis.gridCompColumnArr, function () {
                var f = this.options.field,
                    t = this.options.title,
                    v = $(value).attr(f);
                htmlStr += '<div>' + t + ':</div>';
                htmlStr += '<div>' + v + '</div>';
            });
            htmlStr += '</td></tr>';
        });
        htmlStr += '</tbody>';
    }
    return htmlStr;
}
619611
function createWorksheetRequest(options) {
    options = options || {};

    // TODO: needs to handle overflow cases and create ore dynamically
    var rowCount = util.coerceNumber(options.rowCount || 5000);
    var colCount = util.coerceNumber(options.colCount || 50);

    options.rowCount = Math.max(rowCount, 10);
    options.colCount = Math.max(colCount, 10);

    var xw = createXMLWriter()
        .startElement('title')
        .text(options.title)
        .endElement()
        .startElement('gs:rowCount')
        .text(options.rowCount)
        .endElement()
        .startElement('gs:colCount')
        .text(options.colCount)
        .endElement()
        .endElement();

    return xw.toString();
}
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;
    }