WeihanLi.Npoi 1.7.0 更新
程序员文章站
2022-03-25 18:01:39
WeihanLi.Npoi 1.7.0 版本,增加了 `ColumnInputFormatter`/`ColumnOutputFormatter`,又进一步增强了导入导出的灵活性 ......
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
上一篇: Java 获取PDF表单域的值
下一篇: MySQL 5.5.28 发布
推荐阅读
-
火狐浏览器更新到新版本之后 禁用JS的选项没有了的解决方法
-
Win10创造者更新15025快速预览版今日推送:适用于64位版本系统
-
Win10创作者更新15025预览版已修复和已知问题汇总
-
win10创造者更新升级补丁14393.729下载 64位
-
Win10旗舰HP Elite X3获第四次固件更新:提升性能/修复问题
-
Win10 PC版创作者更新预览版15019修复和改进内容汇总
-
Win10创作者更新15019怎么样? 新功能上手视频演示
-
Win10创造者更新15025预览版ISO镜像微软官方下载 含32位
-
Win10 Mobile创造者更新15025预览版已知问题汇总
-
3.26日百度更新致大量网站快照回档 收录下降