/// <summary> /// 由SheetFormatterContainer集合导出基于多工作薄的EXCEL模板的文件 /// </summary> /// <param name="templatePath">模板路径</param> /// <param name="formatterContainers">模板数据格式化容器字典(Key:Sheet名称,Value:模板数据格式化容器对象)</param> /// <param name="filePath">导出路径,可选</param> /// <returns></returns> public static string ToExcelWithTemplate(string templatePath, IDictionary <string, SheetFormatterContainer> formatterContainers, string filePath = null) { ExcelCommon.CheckTemplateAndExportPath(templatePath, ref filePath); if (string.IsNullOrEmpty(filePath)) { return(null); } string templateConfigFilePath = ExcelCommon.GetTemplateConfigFilePath(templatePath, false); var workbookParameterContainer = new WorkbookParameterContainer(); workbookParameterContainer.Load(templateConfigFilePath); List <SheetFormatter> sheetFormatterList = new List <SheetFormatter>(); foreach (var item in formatterContainers) { SheetParameterContainer sheetParameterContainer = workbookParameterContainer[item.Key]; sheetFormatterList.Add(new SheetFormatter(item.Key, item.Value.GetFormatters(sheetParameterContainer))); } ExportHelper.ExportToLocal(templatePath, filePath, sheetFormatterList.ToArray()); return(filePath); }
/// <summary> ///由SheetFormatterContainer导出基于EXCEL模板的文件 /// </summary> /// <param name="templatePath">模板路径</param> /// <param name="sheetName">模板中使用的工作薄名称</param> /// <param name="formatterContainer">模板数据格式化容器</param> /// <param name="filePath">导出路径,可选</param> /// <returns></returns> public static string ToExcelWithTemplate(string templatePath, string sheetName, SheetFormatterContainer formatterContainer, string filePath = null) { ExcelCommon.CheckTemplateAndExportPath(templatePath, ref filePath); if (string.IsNullOrEmpty(filePath)) { return(null); } string templateConfigFilePath = ExcelCommon.GetTemplateConfigFilePath(templatePath, false); var workbookParameterContainer = new WorkbookParameterContainer(); workbookParameterContainer.Load(templateConfigFilePath); SheetParameterContainer sheetParameterContainer = workbookParameterContainer[sheetName]; ExportHelper.ExportToLocal(templatePath, filePath, new SheetFormatter(sheetName, formatterContainer.GetFormatters(sheetParameterContainer))); return(filePath); }