rigofunc / npoi.extension Goto Github PK
View Code? Open in Web Editor NEWThis repo contains the extension for the NPOI, which provides IEnumerable<T> have save to and load from excel functionalities.
License: Apache License 2.0
This repo contains the extension for the NPOI, which provides IEnumerable<T> have save to and load from excel functionalities.
License: Apache License 2.0
1.export to excel just fine,but when loading excel file,I came across a lot of formatter problems.(even use the excel file generate by this extension).
2.suggestions:Will you plan to support multiple Statistics instance,I need sum,avg when exporting excel.
3.suggestions:will you plan to support custom format cell other than just customize datetime
背景
在导入excel时,需要动态的决定那些行是真实的有效行数据
例如:当第二列没填值时,这一行为无效数据,输出结果中不应该包含这一行数据
建议
增加参数Func<IRow, bool> customerRowsFilter = null),在处理每行数据时先校验传入的委托,决定是否要加入到输出结果中
public static IEnumerable Load(string excelFile, int startRow = 1, int sheetIndex = 0, ValueConverter valueConverter = null, Func<IRow, bool> customerRowsFilter = null) where T : class, new()
The default date time formatter is yyyy-MM-dd HH:mm:ss
, but user can set by following code
Excel.Setting.DateFormatter = "yyyy-MM-dd";
NpoiExtension.cs 113行,值类型判断不包含GUID类型,如果导出model存在GUID,则出错
this extension really a great time saver.But In my practice,most of times i just simply to convert database data to excel files.it is tedious to map db structures to class files.so i think it will be better to just simply transform a datatable/dataset to excel file(s).But it seems that currently this extension does not support datatable.
so,I looking forward that datatable to excel will be supported in the next version for barely transfer db to excel without and modifications.
This will be released as v2.0.0
2个方法的参数是什么意思
在property.PropertyType == typeof(DateTime)这个else if判断分支,要加上或者等于DateTime?,并且修改Convert.ToDateTime为其它方法才行。
else if (property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?))
{
if (dateCellStyle == null)
{
// create the cache.
dateCellStyle = workbook.CreateCellStyle();
var dateFormat = workbook.CreateDataFormat();
dateCellStyle.DataFormat = dateFormat.GetFormat(Excel.Setting.DateFormatter);
}
cell.CellStyle = dateCellStyle;
**DateTime? time = value.ChangeType((DateTime?)null);
if (time.HasValue)
{
cell.SetCellValue(time.Value);
}
else
{
cell.SetCellValue("");
}**
}
This will be a new repo in Npoi.Core
Right now, only the datetime cell value can specify the formatter, plan to support more custom formatters for cell value when v2.1
release.
The Excel.Load(excelFile) doesn't use the fluent api, will be fixed when v2.1 released next month
1.如果可以,能否把代码注释一起打包?
2.对于输出到 工作簿表格文件,有考虑过要设计一个开关 是否覆盖与重新创建的操作吗?
After v2.1 released, I'll rename this to Arch/Excel
or other something better, attribute based configuration will not be supported, only fluent configuration api will be supported.
case CellType.Numeric: if (HSSFDateUtil.IsCellDateFormatted(cell))//日期类型 { if (!string.IsNullOrEmpty(cellConfig?.Formatter)) { return cell.DateCellValue.ToString(cellConfig?.Formatter); } return cell.DateCellValue.ToString(); } else//其他数字类型 { return cell.ToString(); }
背景
在导入Excel时
excel文件如下:
单元格A2:A2
单元格B2:=CONCATENATE("test", A2)
实体类
public ExcelData{
[Column(Index = 0)]
public string A{get;set;}
[Column(Index = 1)]
public string B{get;set;}
}
var data = Excel.Load(file, sheetIndex: 1);
期望结果及实际结果
期望data 的B属性为:testA2
实际结果为:CONCATENATE("test", A2)
Update NPOI to v2.2.1
There are some issues about fluent api, but had fixed by FluentExcel, please use FluentExcel
in your code
Property
;A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.