<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/shps951023/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/shps951023/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/shps951023/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
</p>
</div>
---
<div align="center">
<p><strong><a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.zh-Hant.md">繁體中文</a></strong></p>
</div>
---
<div align="center">
Your <a href="https://github.com/shps951023/MiniExcel">Star</a> and <a href="https://miniexcel.github.io">Donate</a> can make MiniExcel better
</div>
---
### Introduction
MiniExcel is simple and efficient to avoid OOM's .NET processing Excel tool.
At present, most popular frameworks need to load all the data into the memory to facilitate operation, but it will cause memory consumption problems. MiniExcel tries to use algorithm from a stream to reduce the original 1000 MB occupation to a few MB to avoid OOM(out of memory).

### Features
- Low memory consumption, avoid OOM (out of memory) and full GC
- Support `real-time` operation of each row of data
- Support LINQ deferred execution, it can do low-consumption, fast paging and other complex queries
- Lightweight, without Microsoft Office installed, no COM+, DLL size is less than 150KB
- Easy API style to read/write/fill excel
### Get Started
- [Import/Query Excel](#getstart1)
- [Export/Create Excel](#getstart2)
- [Excel Template](#getstart3)
- [Excel Column Name/Index/Ignore Attribute](#getstart4)
- [Examples](#getstart5)
### Installation
You can install the package [from NuGet](https://www.nuget.org/packages/MiniExcel)
### Release Notes
Please Check [Release Notes](docs)
### TODO
Please Check [TODO](https://github.com/shps951023/MiniExcel/projects/1?fullscreen=true)
### Performance
Benchmarks logic can be found in [MiniExcel.Benchmarks](benchmarks/MiniExcel.Benchmarks/Program.cs) , and test cli
```bash
dotnet run -p .\benchmarks\MiniExcel.Benchmarks\ -c Release -f netcoreapp3.1 -- -f * --join
```
Output from the latest run is :
```bash
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-7700 CPU 3.60GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET Framework 4.8 (4.8.4341.0), X64 RyuJIT
Job-ZYYABG : .NET Framework 4.8 (4.8.4341.0), X64 RyuJIT
IterationCount=3 LaunchCount=3 WarmupCount=3
```
Benchmark History : [Link](https://github.com/shps951023/MiniExcel/issues/276)
#### Import/Query Excel
Logic : [**Test1,000,000x10.xlsx**](benchmarks/MiniExcel.Benchmarks/Test1%2C000%2C000x10.xlsx) as performance test basic file, 1,000,000 rows * 10 columns "HelloWorld" cells, 23 MB file size
| Library | Method | Max Memory Usage | Mean |
| ---------------------------- | -------------: | ---------------: | ---------------: |
| MiniExcel | 'MiniExcel QueryFirst' | 0.109 MB | 0.0007264 sec |
| ExcelDataReader | 'ExcelDataReader QueryFirst' | 15.24 MB | 10.66421 sec |
| MiniExcel | 'MiniExcel Query' | 17.3 MB | 14.17933 sec |
| ExcelDataReader | 'ExcelDataReader Query' | 17.3 MB | 22.56508 sec |
| Epplus | 'Epplus QueryFirst' | 1,452 MB | 18.19801 sec |
| Epplus | 'Epplus Query' | 1,451 MB | 23.64747 sec |
| OpenXmlSDK | 'OpenXmlSDK Query' | 1,412 MB | 52.00327 sec |
| OpenXmlSDK | 'OpenXmlSDK QueryFirst' | 1,413 MB | 52.34865 sec |
| ClosedXml | 'ClosedXml QueryFirst' | 2,158 MB | 66.18897 sec |
| ClosedXml | 'ClosedXml Query' | 2,184 MB | 191.43412 sec |
#### Export/Create Excel
Logic : create a total of 10,000,000 "HelloWorld" excel
| Library | Method | Max Memory Usage | Mean |
| ------------------------ | -------------: | ---------------: | -----------: |
| MiniExcel | 'MiniExcel Create Xlsx' | 15 MB | 11.53181 sec |
| Epplus | 'Epplus Create Xlsx' | 1,204 MB | 22.50971 sec |
| OpenXmlSdk | 'OpenXmlSdk Create Xlsx' | 2,621 MB | 42.47399 sec |
| ClosedXml | 'ClosedXml Create Xlsx' | 7,141 MB | 140.93992 sec |
### Excel Query/Import <a name="getstart1"></a>
#### 1. Execute a query and map the results to a strongly typed IEnumerable [[Try it]](https://dotnetfiddle.net/w5WD1J)
Recommand to use Stream.Query because of better efficiency.
```csharp
public class UserAccount
{
public Guid ID { get; set; }
public string Name { get; set; }
public DateTime BoD { get; set; }
public int Age { get; set; }
public bool VIP { get; set; }
public decimal Points { get; set; }
}
var rows = MiniExcel.Query<UserAccount>(path);
// or
using (var stream = File.OpenRead(path))
var rows = stream.Query<UserAccount>();
```

#### 2. Execute a query and map it to a list of dynamic objects without using head [[Try it]](https://dotnetfiddle.net/w5WD1J)
* dynamic key is `A.B.C.D..`
| MiniExcel | 1 |
| -------- | -------- |
| Github | 2 |
```csharp
var rows = MiniExcel.Query(path).ToList();
// or
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);
}
```
#### 3. Execute a query with first header row [[Try it]](https://dotnetfiddle.net/w5WD1J)
note : same column name use last right one
Input Excel :
| Column1 | Column2 |
| -------- | -------- |
| MiniExcel | 1 |
| Github | 2 |
```csharp
var rows = MiniExcel.Query(useHeaderRow:true).ToList();
// or
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);
}
```
#### 4. Query Support LINQ Extension First/Take/Skip ...etc
Query First
```csharp
var row = MiniExcel.Query(path).First();
Assert.Equal("HelloWorld", row.A);
// or
using (var stream = File.OpenRead(path))
{
var row = stream.Query().First();
Assert.Equal("HelloWorld", row.A);
}
```
Performance between MiniExcel/ExcelDataReader/ClosedXML/EPPlus

#### 5. Query by sheet name
```csharp
MiniExcel.Query(path, sheetName: "SheetName");
//or
stream.Query(sheetName: "SheetName");
```
#### 6. Query all sheet name and rows
```csharp
var sheetNames = MiniExcel.GetSheetNames(path);
foreach (var sheetName in sheetNames)
{
var rows = MiniExcel.Query(path, sheetName: sheetName);
}
```
#### 7. Get Columns
```csharp
var columns = MiniExcel.GetColumns(
修改后的MiniExcel源码
需积分: 0 122 浏览量
更新于2024-03-14
收藏 58.18MB ZIP 举报
MiniExcel是一款专为.NET开发者设计的轻量级库,用于快速、高效地处理Excel文件,尤其在处理大数据量时,其优化的内存管理机制能够有效防止OOM(Out of Memory)异常。这个“修改后的MiniExcel源码”版本,据描述,主要解决了在导出Excel文件时单元格字体变化的问题,这在实际应用中是非常关键的一点,因为保持数据格式的一致性对于用户来说至关重要。
我们要理解MiniExcel的基本工作原理。它主要通过提供API接口,使得开发者可以方便地读取、写入和填充Excel数据。MiniExcel支持多种操作,如读取单个单元格、整行或整列,以及批量写入数据。此外,它还允许自定义样式,包括字体、颜色、对齐方式等,以满足不同场景的需求。
在原版MiniExcel中,可能出现的问题可能是因为在处理大量单元格时,字体设置没有正确地持久化到导出的Excel文件中,导致导出后单元格的字体与预设的不一致。这个问题可能是由于内部样式管理机制的漏洞或者在处理Excel样式对象时的bug引起的。修改后的源码针对这个问题进行了修复,确保了在写入数据的同时,也能保留正确的字体设置。
要深入了解这个修复,我们需要查看源代码中的关键部分。MiniExcel通常会有一个内部样式管理器,用于缓存和重用样式对象,以减少内存开销。修复可能涉及检查和更新这个管理器的逻辑,确保在创建新的单元格样式时,能够正确地复制和应用字体属性。此外,写入Excel文件的过程中,可能还需要更新了对Excel文档格式(如XLSX或CSV)的处理,以正确序列化和存储字体信息。
使用修改后的MiniExcel源码,开发者可以更安心地在项目中集成这个库,不用担心因字体变化导致的数据展示问题。同时,这也体现了开源社区的力量,通过不断迭代和修复,提高软件的质量和稳定性。
在实际开发中,我们需要注意以下几点:
1. 更新MiniExcel库到最新版本,包括这个修复的版本,以避免遇到已知问题。
2. 在写入Excel时,正确设置字体样式,包括字号、颜色、粗细、斜体等,确保导出文件与预期一致。
3. 对于大量数据操作,利用MiniExcel提供的批处理功能,以提高性能并减少内存消耗。
4. 在遇到问题时,可以参考MiniExcel的源码,理解其工作原理,甚至可以根据需要进行二次开发。
这个修改后的MiniExcel源码版本是.NET开发人员处理Excel文件的一个可靠选择,尤其对于那些重视数据格式一致性的项目。通过深入研究源码,开发者不仅可以学习到如何高效处理Excel数据,还能了解到如何调试和优化代码,提升自己的编程技能。

wee371
- 粉丝: 33
最新资源
- 2017年全国职业院校技能大赛网络空间安全申报方案.docx
- 利用VBA进行结构化数据审计研究.docx
- 智能太阳能热水器水温水位单片机控制仪设计.doc
- 学生信息管理系统-C语言.doc
- 通信工程单位分部分项检验批.doc
- 软件开发集成与实施项目总体设计说明书.pdf
- 翻转课堂在初中计算机教学中的应用.docx
- 基于单片机的病床呼叫系统大学本科方案设计书09384.doc
- 基于法学理论视角的信息网络传播法研究.docx
- 模板其他企业信息化项目可行性研究报告.doc
- 智能工程的概念人工智能智能工程.ppt
- 中小企业网络管理员实用教程(2).ppt
- 计算机网络技术考试试题.doc
- 互联网医疗相关各大APP及产品对比及解读.docx
- 高速网络加速大数据与深度学习.pdf
- 大数据时代下企业会计信息化策略探析.docx