WeihanLi.Npoi 1.7.0 更新
WeihanLi.Npoi 1.7.0 更新介绍
Intro
昨天晚上发布了 WeihanLi.Npoi 1.7.0 版本,增加了 ColumnInputFormatter/ColumnOutputFormatter,又进一步增强了导入导出的灵活性,来看下面的示例
ColumnInputFormatter/ColumnOutputFormatter
示例 Model:
internal abstract class BaseEntity
{
public int PKID { get; set; }
}
internal class TestEntity : BaseEntity
{
public Guid SettingId { get; set; }
public string SettingName { get; set; }
public string DisplayName { get; set; }
public string SettingValue { get; set; }
public string CreatedBy { get; set; } = "liweihan";
public DateTime CreatedTime { get; set; } = DateTime.Now;
public string UpdatedBy { get; set; }
public DateTime UpdatedTime { get; set; }
public bool Enabled { get; set; }
}
示例配置:
var setting = ExcelHelper.SettingFor<TestEntity>();
// ExcelSetting
setting.HasAuthor("WeihanLi")
.HasTitle("WeihanLi.Npoi test")
.HasDescription("WeihanLi.Npoi test")
.HasSubject("WeihanLi.Npoi test");
setting.HasSheetConfiguration(0, "SystemSettingsList", 1, true);
// setting.HasFilter(0, 1).HasFreezePane(0, 1, 2, 1);
setting.Property(_ => _.SettingId)
.HasColumnIndex(0);
setting.Property(_ => _.SettingName)
.HasColumnTitle("SettingName")
.HasColumnIndex(1);
setting.Property(_ => _.DisplayName)
.HasOutputFormatter((entity, displayName) => $"AAA_{entity.SettingName}_{displayName}")
.HasInputFormatter((entity, originVal) => originVal.Split(new[] { '_' })[2])
.HasColumnTitle("DisplayName")
.HasColumnIndex(2);
setting.Property(_ => _.SettingValue)
.HasColumnTitle("SettingValue")
.HasColumnIndex(3);
setting.Property(_ => _.CreatedTime)
.HasColumnTitle("CreatedTime")
.HasColumnIndex(4)
.HasColumnWidth(10)
.HasColumnFormatter("yyyy-MM-dd HH:mm:ss");
setting.Property(_ => _.CreatedBy)
.HasColumnInputFormatter(x => x += "_test")
.HasColumnIndex(4)
.HasColumnTitle("CreatedBy");
setting.Property(x => x.Enabled)
.HasColumnInputFormatter(val => "启用".Equals(val))
.HasColumnOutputFormatter(v => v ? "启用" : "禁用");
setting.Property("HiddenProp")
.HasOutputFormatter((entity, val) => $"HiddenProp_{entity.PKID}");
setting.Property(_ => _.PKID).Ignored();
setting.Property(_ => _.UpdatedBy).Ignored();
setting.Property(_ => _.UpdatedTime).Ignored();
测试代码:
var entities = new List<TestEntity>()
{
new TestEntity()
{
PKID = 1,
SettingId = Guid.NewGuid(),
SettingName = "Setting1",
SettingValue = "Value1",
DisplayName = "ddd1"
},
new TestEntity()
{
PKID=2,
SettingId = Guid.NewGuid(),
SettingName = "Setting2",
SettingValue = "Value2",
Enabled = true
},
};
var path = $@"{tempDirPath}\test.xlsx";
entities.ToExcelFile(path);
var entitiesT0 = ExcelHelper.ToEntityList<TestEntity>(path);
导出结果:

导入结果:


More
新版本发布,快来尝鲜吧~
ColumnInputFormatter 结合之前的 InputFormatter/OutputFormatter 能够帮助你更灵活的导入导出,快来试试吧~~
Reference
- https://github.com/WeihanLi/WeihanLi.Npoi
- https://github.com/WeihanLi/WeihanLi.Npoi/blob/dev/samples/DotNetCoreSample/Program.cs
- https://www.nuget.org/packages/WeihanLi.Npoi/
WeihanLi.Npoi 1.7.0 更新的更多相关文章
- WeihanLi.Npoi 1.10.0 更新日志
WeihanLi.Npoi 1.10.0 更新日志 Intro 上周有个网友希望能够导入Excel时提供一个 EndRowIndex 来自己控制结束行和根据字段过滤的,周末找时间做了一下这个 feat ...
- WeihanLi.Npoi 1.13.0 更新日志
WeihanLi.Npoi 1.13.0 更新日志 Intro 在 Github 上收到 Issue 收到网友反馈希望支持自动分 Sheet 导出,有兴趣的可以参考 Issue https://git ...
- WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes Intro 最近 NPOI 扩展新更新了两个版本,感谢 shaka chow 的帮忙和支持,这两个 Feature ...
- WeihanLi.Npoi 1.14.0 Release Notes
WeihanLi.Npoi 1.14.0 Release Notes Intro 周末更新了一下项目,开始使用可空引用类型,并且移除了 net45 的支持,仅支持 netstandard2.0 Cha ...
- WeihanLi.Npoi 1.16.0 Release Notes
WeihanLi.Npoi 1.16.0 Release Notes Intro 最近有网友咨询如何设置单元格样式,在之前的版本中是不支持的,之前主要考虑的是数据,对于导出的样式并没有支持,这个 is ...
- WeihanLi.Npoi 近期更新
WeihanLi.Npoi 近期更新 Intro 最近对我的 NPOI 扩展做了一些改变,一方面提高性能,一方面修复bug,增加一些新的功能来让它更加好用,前几天发布了 1.5.0 版本,下面来介绍一 ...
- WeihanLi.Npoi
WeihanLi.Npoi Intro Npoi 扩展,适用于.netframework4.5及以上和netstandard2.0, .netframework基于NPOI, .netstandard ...
- 使用 WeihanLi.Npoi 操作 CSV
使用 WeihanLi.Npoi 操作 CSV Intro 最近发现 csv 文件在很多情况下都在使用,而且经过大致了解,csv 格式简单,相比 excel 文件要小很多,读取也很是方便,而且也很通用 ...
- ASP.NET MVC 4.0 中使用NPOI 2.2.0 按模板生成Excel报表
使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写.NPOI是构建在POI 3.x版本之上的,它可以在没有安装Office的情况下对Word/ ...
随机推荐
- oracle函数 CHR(n1)
[功能]:将ASCII 码转换为字符. [参数]:n1,为0 ~ 255,整数 [返回]:字符型 [示例] SQL> select chr(54740) zhao,chr(65) chr65 f ...
- Layer(Web弹窗)
Layer弹窗的用法: <script src="jQuery的路径"></script> <!-- 你必须先引入jQuery1.8或以上版本 --& ...
- win10提示 磁盘包含不是“PARTITION_BASIC_DATA_GUID"类型的分区
在win10创建新的磁盘分区的时候,有时候会提示 磁盘包含不是"PARTITION_BASIC_DATA_GUID"类型的分区 如果你试了其他方法都不凑效,那么看看你已经有几个盘( ...
- NLP突破性成果 BERT 模型详细解读 bert参数微调
https://zhuanlan.zhihu.com/p/46997268 NLP突破性成果 BERT 模型详细解读 章鱼小丸子 不懂算法的产品经理不是好的程序员 关注她 82 人赞了该文章 Goo ...
- Tensorflow中tf.ConfigProto()详解
参考Tensorflow Machine Leanrning Cookbook tf.ConfigProto()主要的作用是配置tf.Session的运算方式,比如gpu运算或者cpu运算 具体代码如 ...
- Codeforces Round #577 (Div 2)
A. Important Exam 水题 #include<iostream> #include<string.h> #include<algorithm> #in ...
- 分布式TensorFlow集群local server使用详解
通过local server理解分布式TensorFlow集群的应用与实现. 简介 TensorFlow从0.8版本开始,支持分布式集群,并且自带了local server方便测试. Local ...
- HTML5的5个的新特性
特性1:正则表达式 无须使用服务端的检测,使用浏览器的本地功能,就可以帮助你判断邮箱的格式,URL,电话,防止用户输入错误的信息,通过H5的pattern属性,很方便的整合这个功能. <inpu ...
- 梯度下降优化算法综述与PyTorch实现源码剖析
现代的机器学习系统均利用大量的数据,利用梯度下降算法或者相关的变体进行训练.传统上,最早出现的优化算法是SGD,之后又陆续出现了AdaGrad.RMSprop.ADAM等变体,那么这些算法之间又有哪些 ...
- Codeforces Round #190 (Div. 1 + Div. 2)
A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...