基于模板、注解的多sheet导出{@code Map[String, List[?]]}类型数据
模板定制详见定制说明

@param sheetWrappers sheet包装类
@param templatePath  Excel模板
@param targetPath    导出Excel路径
@throws Excel4JException 异常
167839
public void mapSheet2Excel(List<MapSheetWrapper> sheetWrappers, String templatePath, String targetPath)
            throws Excel4JException {

        try (SheetTemplate sheetTemplate = exportExcelByMapHandler(sheetWrappers, templatePath)) {
            sheetTemplate.write2File(targetPath);
        } catch (IOException e) {
            throw new Excel4JException(e);
        }
    }
193911
public static boolean WriteXml(ExcelConfig dlExcel, String xmlPath) throws Exception {
        //写入xml
        return XmlUtil.toXml(dlExcel, new File(xmlPath));
    }
1167469
public function generateFile(string $targetPath, string $templateName, array $variables)
    {
        $variables = array_merge($variables, [
            'helper' => $this->twigHelper,
        ]);

        $this->addOperation($targetPath, $templateName, $variables);
    }
1013876
public function map($sourcePath, $targetPath)
  {
    if (file_exists($sourcePath)) {
      $items = array();
      if (is_file($sourcePath)) {
        $items[$targetPath] = $sourcePath;
      } elseif (is_dir($sourcePath)) {
        $finder = new Finder\Finder();
        foreach ($finder->in($sourcePath)->files() as $file) {
          /* @var $file Finder\SplFileInfo */
          $fileTargetPath = $targetPath . "/" . $file->getRelativePathname();
          $items[$fileTargetPath] = $file->getPathname();
        }
      }

      foreach ($items as $target => $source) {
        $formulae = new AssetFormulae();
        $formulae->setInputs(
          array($source)
        );
        $formulae->setOptions(
          array("output" => $target)
        );

        $this->append($formulae);
      }
    }
  }
568411
public static boolean list2Xls(ExcelConfig config, List<?> list, String filePath, String fileName) throws Exception {
        //创建目录
        File file = new File(filePath);
        if (!(file.exists())) {
            if (!file.mkdirs()) {
                throw new RuntimeException("创建导出目录失败!");
            }
        }
        OutputStream outputStream = null;
        try {
            if (!fileName.toLowerCase().endsWith(EXCEL)) {
                fileName += EXCEL;
            }
            File excelFile = new File(filePath + "/" + fileName);
            outputStream = new FileOutputStream(excelFile);
            return list2Xls(config, list, outputStream);
        } catch (Exception e1) {
            return false;
        } finally {
            if(outputStream != null){
                outputStream.close();
            }
        }
    }
1003555
public void runWholeFilesetPasses(SoyFileSetNode soyTree, TemplateRegistry templateRegistry) {
    ImmutableList<SoyFileNode> sourceFiles = ImmutableList.copyOf(soyTree.getChildren());
    IdGenerator idGenerator = soyTree.getNodeIdGenerator();
    for (CompilerFileSetPass pass : crossTemplateCheckingPasses) {
      CompilerFileSetPass.Result result = pass.run(sourceFiles, idGenerator, templateRegistry);
      if (result == CompilerFileSetPass.Result.STOP) {
        break;
      }
    }
  }
1154743
public static CMISObjectWrapper wrap(final GraphObject source, final String propertyFilter, final Boolean includeAllowableActions) throws FrameworkException {

		CMISObjectWrapper wrapper = null;
		if (source != null) {

			final CMISInfo cmisInfo = source.getCMISInfo();
			if (cmisInfo != null) {

				final BaseTypeId baseTypeId = cmisInfo.getBaseTypeId();
				if (baseTypeId != null) {

					switch (baseTypeId) {

						case CMIS_DOCUMENT:
							wrapper = new CMISDocumentWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getDocumentInfo());
							break;

						case CMIS_FOLDER:
							wrapper = new CMISFolderWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getFolderInfo());
							break;

						case CMIS_ITEM:
							wrapper = new CMISItemWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getItemInfo());
							break;

						case CMIS_POLICY:
							wrapper = new CMISPolicyWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getPolicyInfo());
							break;

						case CMIS_RELATIONSHIP:
							wrapper = new CMISRelationshipWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getRelationshipInfo());
							break;

						case CMIS_SECONDARY:
							wrapper = new CMISSecondaryWrapper(propertyFilter, includeAllowableActions);
							wrapper.initializeFrom(cmisInfo.getSecondaryInfo());
							break;
					}
				}
			}
		}

		return wrapper;
	}
630269
public void write2File(String filePath) throws Excel4JException {

        try (FileOutputStream fos = new FileOutputStream(filePath)) {
            this.workbook.write(fos);
        } catch (IOException e) {
            throw new Excel4JException(e);
        }
    }
847337
public void generateXls(OutputStream out, List<Map<String, Object>> rows, List<ColumnDef> columns) {
        try {
            Workbook wb = new HSSFWorkbook();  // or new XSSFWorkbook();
            String safeName = WorkbookUtil.createSafeSheetName("Report"); // returns " O'Brien's sales   "
            Sheet reportSheet = wb.createSheet(safeName);

            short rowc = 0;
            Row nrow = reportSheet.createRow(rowc++);
            short cellc = 0;
            if (rows == null) return;
            if (columns == null && rows.size() > 0)
            {
                columns = new ArrayList<ColumnDef>(CollectionUtils.collect(rows.get(0).keySet(), new Transformer() {
                    @Override
                    public Object transform(final Object input) {
                        return new ColumnDef()
                        {{
                                setName((String)input);
                            }};
                    }
                }));
            }
            if (columns != null)
            {
                for (ColumnDef column : columns)
                {
                    Cell cell = nrow.createCell(cellc++);
                    cell.setCellValue(column.getName());
                }
            }
            for (Map<String, Object> row : rows)
            {
                nrow = reportSheet.createRow(rowc++);
                cellc = 0;
                for (ColumnDef column : columns)
                {
                    Cell cell = nrow.createCell(cellc++);
                    cell.setCellValue(String.valueOf(row.get(column.getName())));
                }
            }
            wb.write(out);
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }
888203
public static void compressList(String srcFilePath, String destFilePath) throws Exception {
		File src = new File(srcFilePath);
		if (!src.exists() || !src.isDirectory()) {
			throw new RuntimeException(srcFilePath + "不存在");
		}
		File zipFile = new File(destFilePath);
		ZipOutputStream zos=null;
		try {
			FileOutputStream fos = new FileOutputStream(zipFile);
			CheckedOutputStream cos = new CheckedOutputStream(fos, new CRC32());
			zos = new ZipOutputStream(cos);
			String baseDir = "";
			File[] files = src.listFiles();
			for (File file : files) {
				compressbyType(file, zos, baseDir);
			}			
		} finally {
			if(zos!=null)
			{
				zos.close();
			}
		}
	}
1017800
public static void checkMapColumns(final Sheet sheet, final Class<?> recordClass,
            final List<RecordHeader> headers, final AnnotationReader reader, final Configuration config)
                    throws CellNotFoundException {
        
        List<FieldAccessor> properties = FieldAccessorUtils.getPropertiesWithAnnotation(recordClass, reader, XlsMapColumns.class);
        
        for(FieldAccessor property : properties) {
            final XlsMapColumns mapColumns = property.getAnnotation(XlsMapColumns.class).get();
            if(mapColumns.optional()) {
                continue;
            }
            
            final String previousColumnName = mapColumns.previousColumnName();
            boolean foundPrevious = headers.stream()
                .filter(info -> Utils.matches(info.getLabel(), previousColumnName, config))
                .findFirst()
                .isPresent();
            
            if(!foundPrevious) {
                throw new CellNotFoundException(sheet.getSheetName(), previousColumnName);
            }
            
            final String nextColumnName = mapColumns.nextColumnName();
            if(!nextColumnName.isEmpty()) {
                boolean foundNext = headers.stream()
                        .filter(info -> Utils.matches(info.getLabel(), nextColumnName, config))
                        .findFirst()
                        .isPresent();
                
                if(!foundNext) {
                    throw new CellNotFoundException(sheet.getSheetName(), nextColumnName);
                }
            }
            
        }
    }
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);
        }
    }
35577
static void copyResources(URL resourceUrl, File targetPath) throws IOException, URISyntaxException {
        if (resourceUrl == null) {
            return;
        }

        URLConnection urlConnection = resourceUrl.openConnection();

        /**
         * Copy resources either from inside jar or from project folder.
         */
        if (urlConnection instanceof JarURLConnection) {
            copyJarResourceToPath((JarURLConnection) urlConnection, targetPath);
        } else if (VFS_PROTOCOL.equals(resourceUrl.getProtocol())) {
            VirtualFile virtualFileOrFolder = VFS.getChild(resourceUrl.toURI());
            copyFromWarToFolder(virtualFileOrFolder, targetPath);
        } else {
            File file = new File(resourceUrl.getPath());
            if (file.isDirectory()) {
                for (File resourceFile : FileUtils.listFiles(file, null, true)) {
                    int index = resourceFile.getPath().lastIndexOf(targetPath.getName()) + targetPath.getName().length();
                    File targetFile = new File(targetPath, resourceFile.getPath().substring(index));
                    if (!targetFile.exists() || targetFile.length() != resourceFile.length()) {
                        if (resourceFile.isFile()) {
                            FileUtils.copyFile(resourceFile, targetFile);
                        }
                    }
                }
            } else {
                if (!targetPath.exists() || targetPath.length() != file.length()) {
                    FileUtils.copyFile(file, targetPath);
                }
            }
        }
    }
637777
public ParallelTaskBuilder setTargetHostsFromLineByLineText(
            String sourcePath, HostsSourceType sourceType)
            throws TargetHostsLoadException {

        this.targetHosts = targetHostBuilder.setTargetHostsFromLineByLineText(sourcePath,
                sourceType);
        return this;
    }
763425
private void scanUserPaths(PackageSymbol p, boolean includeSourcePath) throws IOException {
        Set<JavaFileObject.Kind> kinds = getPackageFileKinds();

        Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
        classKinds.remove(JavaFileObject.Kind.SOURCE);
        boolean wantClassFiles = !classKinds.isEmpty();

        Set<JavaFileObject.Kind> sourceKinds = EnumSet.copyOf(kinds);
        sourceKinds.remove(JavaFileObject.Kind.CLASS);
        boolean wantSourceFiles = !sourceKinds.isEmpty();

        boolean haveSourcePath = includeSourcePath && fileManager.hasLocation(SOURCE_PATH);

        if (verbose && verbosePath) {
            if (fileManager instanceof StandardJavaFileManager) {
                StandardJavaFileManager fm = (StandardJavaFileManager)fileManager;
                if (haveSourcePath && wantSourceFiles) {
                    List<Path> path = List.nil();
                    for (Path sourcePath : fm.getLocationAsPaths(SOURCE_PATH)) {
                        path = path.prepend(sourcePath);
                    }
                    log.printVerbose("sourcepath", path.reverse().toString());
                } else if (wantSourceFiles) {
                    List<Path> path = List.nil();
                    for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) {
                        path = path.prepend(classPath);
                    }
                    log.printVerbose("sourcepath", path.reverse().toString());
                }
                if (wantClassFiles) {
                    List<Path> path = List.nil();
                    for (Path platformPath : fm.getLocationAsPaths(PLATFORM_CLASS_PATH)) {
                        path = path.prepend(platformPath);
                    }
                    for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) {
                        path = path.prepend(classPath);
                    }
                    log.printVerbose("classpath",  path.reverse().toString());
                }
            }
        }

        String packageName = p.fullname.toString();
        if (wantSourceFiles && !haveSourcePath) {
            fillIn(p, CLASS_PATH,
                   list(CLASS_PATH,
                        p,
                        packageName,
                        kinds));
        } else {
            if (wantClassFiles)
                fillIn(p, CLASS_PATH,
                       list(CLASS_PATH,
                            p,
                            packageName,
                            classKinds));
            if (wantSourceFiles)
                fillIn(p, SOURCE_PATH,
                       list(SOURCE_PATH,
                            p,
                            packageName,
                            sourceKinds));
        }
    }
1254045
public List<DocumentTemplate> findByApplicableToAtPath(final String atPath) {
        final List<DocumentTemplate> templates = repositoryService.allMatches(
                new QueryDefault<>(DocumentTemplate.class,
                        "findByApplicableToAtPath",
                        "atPath", atPath));
        removeTemplatesWithSameDocumentType(templates);
        return templates;
    }
1328375
protected void encodeData(final FacesContext context, final Sheet sheet, final WidgetBuilder wb)
                throws IOException {

        final JavascriptVarBuilder jsData = new JavascriptVarBuilder(null, false);
        final JavascriptVarBuilder jsRowKeys = new JavascriptVarBuilder(null, false);
        final JavascriptVarBuilder jsStyle = new JavascriptVarBuilder(null, true);
        final JavascriptVarBuilder jsRowStyle = new JavascriptVarBuilder(null, false);
        final JavascriptVarBuilder jsReadOnly = new JavascriptVarBuilder(null, true);
        final JavascriptVarBuilder jsRowHeaders = new JavascriptVarBuilder(null, false);

        final boolean isCustomHeader = sheet.getRowHeaderValueExpression() != null;

        final List<Object> values = sheet.getSortedValues();
        int row = 0;
        for (final Object value : values) {
            context.getExternalContext().getRequestMap().put(sheet.getVar(), value);
            final String rowKey = sheet.getRowKeyValueAsString(context);
            jsRowKeys.appendArrayValue(rowKey, true);
            encodeRow(context, rowKey, jsData, jsRowStyle, jsStyle, jsReadOnly, sheet, row);

            // In case of custom row header evaluate the value expression for every row to
            // set the header
            if (sheet.isShowRowHeaders() && isCustomHeader) {
                final String rowHeader = sheet.getRowHeaderValueAsString(context);
                jsRowHeaders.appendArrayValue(rowHeader, true);
            }
            row++;
        }

        sheet.setRowVar(context, null);

        wb.nativeAttr("data", jsData.closeVar().toString());
        wb.nativeAttr("styles", jsStyle.closeVar().toString());
        wb.nativeAttr("rowStyles", jsRowStyle.closeVar().toString());
        wb.nativeAttr("readOnlyCells", jsReadOnly.closeVar().toString());
        wb.nativeAttr("rowKeys", jsRowKeys.closeVar().toString());

        // add the row header as a native attribute
        if (!isCustomHeader) {
            wb.nativeAttr("rowHeaders", sheet.isShowRowHeaders().toString());
        }
        else {
            wb.nativeAttr("rowHeaders", jsRowHeaders.closeVar().toString());
        }
    }