mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-30 02:47:39 +08:00
Migrated repository
docs | ||
drafts | ||
samples/xlsx | ||
src | ||
.gitattributes | ||
.gitignore | ||
LICENSE.md | ||
README.md |
Features
Avoid large file OOM(out of memoery)
by IEnumerable LazyStep By Step getting one row cells
not until all rows read in memory
e.g: Comparison of MiniExcel Query and ExcelDataReader/EPPlus/ClosedXml of reading large Xlsx File- Support .NET Standard 2.0/.NET 4.6/.NET 5
- Mini(40KB) without any third party library dependencies
- Support dynamic/type mapping query and create by AnonymousType/DapperRows/List/Array/Set/Enumrable/DataTable/Dictionary
Installation
You can install the package from NuGet
Execute a query and map it to a list of dynamic objects without using head
MiniExcel | 1 |
---|---|
Github | 2 |
using (var stream = File.OpenRead(path))
{
var rows = stream.Query().ToList();
Assert.Equal("MiniExcel", rows[0].A);
Assert.Equal(1, rows[0].B);
Assert.Equal("Github", rows[1].A);
Assert.Equal(2, rows[1].B);
}
Execute a query with first header row
Column1 | Column2 |
---|---|
MiniExcel | 1 |
Github | 2 |
using (var stream = File.OpenRead(path))
{
var rows = stream.Query(useHeaderRow:true).ToList();
Assert.Equal("MiniExcel", rows[0].Column1);
Assert.Equal(1, rows[0].Column2);
Assert.Equal("Github", rows[1].Column1);
Assert.Equal(2, rows[1].Column2);
}
Create Excel Xlsx file by ICollection Anonymous Type/Datatable
var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.xlsx");
MiniExcel.Create(path, new[] {
new { Column1 = "MiniExcel", Column2 = 1 },
new { Column1 = "Github", Column2 = 2}
});
Datatable:
var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.xlsx");
var table = new DataTable();
{
table.Columns.Add("Column1", typeof(string));
table.Columns.Add("Column2", typeof(decimal));
table.Rows.Add("MiniExcel", 1);
table.Rows.Add("Github", 2);
}
MiniExcel.Create(path, table);
Create File Result :
Column1 | Column2 |
---|---|
MiniExcel | 1 |
Github | 2 |
SaveAs Stream
using (var stream = new FileStream(path, FileMode.CreateNew))
{
stream.SaveAs(values);
}
ASP.NET Core 3.1 Download Excel Xlsx Demo
public class Startup
{
public void ConfigureServices(IServiceCollection services) => services.AddMvc();
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
}
}
public class HomeController : Controller
{
public IActionResult Index()
{
var values = new[] {
new { Column1 = "MiniExcel", Column2 = 1 },
new { Column1 = "Github", Column2 = 2}
};
var stream = new MemoryStream();
stream.SaveAs(values);
return File(stream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"demo.xlsx");
}
}
TODO
Please Check Issues · todo
Release Notes
Please Check Release Notes