Magicodes.IE 2.3重磅发布——.NET Core开源导入导出库
在2.3這一版本的更新中,我們迎來了眾多的使用者、貢獻者,在這個里程碑中我們也添加并修復了一些功能。對于新特點的功能我將在下面進行詳細的描述,當然也歡迎更多的人可以加入進來,再或者也很期待大家來提issues或者PR,您的一個issue或者PR將是我們前進的動力。
公式導出 #88
(https://github.com/dotnetcore/Magicodes.IE/issues/88)
公式導出目前已經在Excel模板導出中支持,我們可以通過如上代碼片段的格式進行將公式應用到我們的Excel導出模板中.
{{Formula::AVERAGE?params=G4:G6}} {{Formula::SUM?params=G4:G6&G4}}增加分欄、分sheet、追加rows導出 #74
(https://github.com/dotnetcore/Magicodes.IE/issues/74)
在該版本中我們支持使用鏈式編程導出我們的Excel,從而起到追加分欄等作用。
在多個DTO導出中我們可以通過如下代碼片段將我們的Excel分欄導出
exporter.Append(list1).SeparateByColumn().Append(list2).ExportAppendData(filePath);導出形式如下所示:
| row 1 col 1 | row 1 col 2 | row1 | |
| row 2 col 1 | row 2 col 2 | row2 |
當然不僅僅是這樣,我們還可以對行進行追加導出,同時我們可以選擇導出額外的Header信息或者不導出
| 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 |
| 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
(https://github.com/dotnetcore/Magicodes.IE/issues/135)
特別感謝 sgalcheung(https://github.com/sgalcheung)添加該特性的導出,具體使用方式如下所示:
class Program{static async Task Main(string[] args){IExporter exporter = new ExcelExporter();// 生成測試數據var personList = GenFu.GenFu.ListOf<Person>();// 導出一個只包含"FirstName", "LastName"列的excelstring 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
轉載是一種動力 分享是一種美德
如果喜歡作者的文章,請關注【麥扣聊技術】訂閱號以便第一時間獲得最新內容。本文版權歸作者和湖南心萊信息科技有限公司共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
原文作者:HueiFeng
文檔官網:docs.xin-lai.com
QQ群:
編程交流群<85318032>?
產品交流群<897857351>
總結
以上是生活随笔為你收集整理的Magicodes.IE 2.3重磅发布——.NET Core开源导入导出库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《ASP.NET Core项目开发实战入
- 下一篇: 听说用 C# 写 TensorFlow