首页 技术 正文
技术 2022年11月8日
0 收藏 357 点赞 1,328 浏览 2487 个字

在2.3这一版本的更新中,我们迎来了众多的使用者、贡献者,在这个里程碑中我们也添加并修复了一些功能。对于新特点的功能我将在下面进行详细的描述,当然也欢迎更多的人可以加入进来,再或者也很期待大家来提issues或者PR,您的一个issue或者PR将是我们前进的动力。

  • 公式导出 #88

公式导出目前已经在Excel模板导出中支持,我们可以通过如上代码片段的格式进行将公式应用到我们的Excel导出模板中.

{{Formula::AVERAGE?params=G4:G6}}
{{Formula::SUM?params=G4:G6&G4}}
  • 增加分栏、分sheet、追加rows导出 #74

在该版本中我们支持使用链式编程导出我们的Excel,从而起到追加分栏等作用。

在多个DTO导出中我们可以通过如下代码片段将我们的Excel分栏导出

exporter.Append(list1).SeparateByColumn().Append(list2).ExportAppendData(filePath);

导出形式如下所示:

header 1 header 2 header1
row 1 col 1 row 1 col 2 row1
row 2 col 1 row 2 col 2 row2

我们还可以通过多个DTO进行多Sheet的导出,如下代码片段所示:

exporter.Append(list1).SeparateBySheet().Append(list2).ExportAppendData(filePath);

当然不仅仅是这样,我们还可以对行进行追加导出,同时我们可以选择导出额外的Header信息或者不导出

exporter.Append(list1).SeparateByRow().Append(list2).ExportAppendData(filePath);
header 1 header 2 header1
row 1 col 1 row 1 col 2 row1
row 2 col 1 row 2 col 2 row2
row 2 col 1 row 2 col 2 row2

或者我们可以这样加入Header信息

exporter.Append(list1).SeparateByRow().AppendHeaders().Append(list2).ExportAppendData(filePath);
header 1 header 2 header1
row 1 col 1 row 1 col 2 row1
row 2 col 1 row 2 col 2 row2
header 1 header 2 header1
row 2 col 1 row 2 col 2 row2
  • 添加对ExpandoObject类型的支持#135

特别感谢 sgalcheung 添加该特性的导出,具体使用方式如下所示:

class Program
{
static async Task Main(string[] args)
{
IExporter exporter = new ExcelExporter();
// 生成测试数据
var personList = GenFu.GenFu.ListOf<Person>(); // 导出一个只包含"FirstName", "LastName"列的excel
string fields = "FirstName,LastName"; // 可自定义导出想要的字段
var expandoObjectList = new List<ExpandoObject>(personList.Count);
var propertyInfoList = new List<PropertyInfo>();
var fieldsAfterSplit = fields.Split(',');
foreach (var field in fieldsAfterSplit)
{
var propertyName = field.Trim();
var propertyInfo = typeof(Person).GetProperty(propertyName); if (propertyInfo == null)
{
throw new Exception($"Property: {propertyName} 没有找到:{typeof(Person)}");
} propertyInfoList.Add(propertyInfo);
} foreach (var person in personList)
{
var shapedObj = new ExpandoObject(); foreach (var propertyInfo in propertyInfoList)
{
var propertyValue = propertyInfo.GetValue(person);
((IDictionary<string, object>)shapedObj).Add(propertyInfo.Name, propertyValue);
} expandoObjectList.Add(shapedObj);
} string filePath = Path.Combine(Directory.GetCurrentDirectory(), "dynamicExportExcel.xlsx");
var result = await exporter.ExportAsByteArray<ExpandoObject>(expandoObjectList);
File.WriteAllBytes(filePath, result);
}
} class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public int Age { get; set; }
public int NumberOfKids { get; set; }
}

感谢大家对Magicodes.IE的支持。关于更多发布信息大家可以参阅:https://github.com/dotnetcore/Magicodes.IE/blob/master/RELEASE.md

https://github.com/dotnetcore/Magicodes.IE

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857