Skip to content

MiniExcelDataReader refactoring#929

Merged
michelebastione merged 5 commits intomini-software:masterfrom
michelebastione:datareader-implementation
Mar 3, 2026
Merged

MiniExcelDataReader refactoring#929
michelebastione merged 5 commits intomini-software:masterfrom
michelebastione:datareader-implementation

Conversation

@michelebastione
Copy link
Contributor

@michelebastione michelebastione commented Mar 2, 2026

I've integrated the implementation of MiniExcelDataReader to fully support nearly all IDataReader methods and turn it into a fully functional data reader. The new implementation also supports asynchronous reads so there's no need for a separate MiniExcelAsynDataReader, which has thus been removed. The MiniExcelDataReaderBase abstract class has also been removed, as its purpose was to hide all the non implemented IDataReader methods from the main MiniExcelDataReader class.
The OpenXmlImporter and CsvImporter classes have been updated to reflect these changes.

This PR fixes #408 as with this change it is now possible to load a DataTable from a MiniExcelDataReader.

Besides this main change, I've also made two other minor refactorings: the class MiniExcelDataReaderWriteAdapter has been removed and the logic for retrieving values from a IDataReader in order to export them has been simplified.

Integrating the implementation of MiniExcelDataReader to fully support nearly all IDataReader methods and turn it into a fully functional data reader. The new implementation also supports asynchronous reads so there's no need for a separate MiniExcelAsynDataReader, which has thus been removed. The MiniExcelDataReaderBase abstract class has also been removed, as it is no longer needed given its purpose was to hide all the non implemented IDataReader methods from the main class.
The OpenXmlImporter and CsvImporter classes have been updated to reflect these changes.
I'm pretty confident this write adapter has never been of much usefulness, but now that MiniExcelDataReader has become a fully implemented IDataReader I think there is no reason to keep it around.
…a reader

There is no usefulness in forcing each field to be retrieved asynchronously since each row is fully loaded in memory anyways. Removing the superfluous IAsyncEnumerables cuts down a lot of overhead.
@michelebastione michelebastione requested a review from izanhzh March 2, 2026 20:33
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the data reading and writing mechanisms within MiniExcel. The primary goal was to consolidate synchronous and asynchronous data reader functionalities into a single, robust MiniExcelDataReader that fully implements the IDataReader interface. This change simplifies the API, reduces code duplication, and enhances compatibility with standard .NET data consumption patterns, such as direct DataTable loading. Additionally, related write adapters and importer methods have been updated to align with this new unified approach, leading to a more cohesive and efficient library.

Highlights

  • Unified Data Reader Implementation: The MiniExcelDataReader has been refactored to fully support nearly all IDataReader methods and now handles both synchronous and asynchronous reads, eliminating the need for a separate MiniExcelAsyncDataReader.
  • Removal of Redundant Classes: The MiniExcelAsyncDataReader and the abstract base class MiniExcelDataReaderBase have been removed, simplifying the data reader architecture. The MiniExcelDataReaderWriteAdapter was also removed.
  • Improved IDataReader Compatibility: The core MiniExcelDataReader now offers comprehensive IDataReader support, enabling scenarios like loading data directly into a DataTable, which addresses issue Getreader报错, Depth,Isclosed,RecordsAffected方法未实现 #408.
  • Streamlined Export Logic: The logic for retrieving values from an IDataReader for export has been simplified, improving efficiency and maintainability.
  • Updated Importers and Writers: The OpenXmlImporter and CsvImporter classes have been updated to integrate with the new unified MiniExcelDataReader, and CsvWriter and OpenXmlWriter have minor adjustments for async operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/MiniExcel.Core/Abstractions/IMiniExcelDataReader.cs
    • Removed GetNameAsync, GetValueAsync, and NextResultAsync methods, as asynchronous functionality is now handled by the unified ReadAsync method.
  • src/MiniExcel.Core/Abstractions/IMiniExcelWriteAdapterAsync.cs
    • Modified GetRowsAsync to return IAsyncEnumerable<CellWriteInfo[]> instead of IAsyncEnumerable<IAsyncEnumerable<CellWriteInfo>>.
  • src/MiniExcel.Core/DataReader/MiniExcelAsyncDataReader.cs
    • Removed the entire file, as its functionality has been merged into the new MiniExcelDataReader.
  • src/MiniExcel.Core/DataReader/MiniExcelDataReader.cs
    • Removed the entire file, as its functionality has been merged into the new MiniExcelDataReader.
  • src/MiniExcel.Core/DataReader/MiniExcelDataReaderBase.cs
    • Removed the entire file, as the base class is no longer needed with the unified MiniExcelDataReader.
  • src/MiniExcel.Core/MiniExcelDataReader.cs
    • Added a new MiniExcelDataReader class that consolidates synchronous and asynchronous IDataReader implementations.
    • Implemented comprehensive IDataReader methods, including GetValue, GetBoolean, GetByte, GetChar, GetDateTime, GetDecimal, GetFloat, GetDouble, GetGuid, GetInt16, GetInt32, GetInt64, GetString, GetValues, IsDBNull, GetName, GetOrdinal, and GetSchemaTable.
    • Provided Create and CreateAsync static factory methods for instantiation.
    • Added Close and Dispose methods for resource management, including DisposeAsync.
  • src/MiniExcel.Core/WriteAdapters/AsyncEnumerableWriteAdapter.cs
    • Updated GetRowsAsync to return IAsyncEnumerable<CellWriteInfo[]>.
    • Refactored GetRowValuesAsync into a synchronous GetRowValues method that returns CellWriteInfo[].
  • src/MiniExcel.Core/WriteAdapters/MiniExcelDataReaderWriteAdapter.cs
    • Removed the entire file, as its purpose is now handled by the unified MiniExcelDataReader.
  • src/MiniExcel.Core/WriteAdapters/MiniExcelWriteAdapterFactory.cs
    • Removed the logic for creating MiniExcelDataReaderWriteAdapter instances.
  • src/MiniExcel.Csv/Api/CsvImporter.cs
    • Updated using directives to reflect the new MiniExcel.Core namespace.
    • Modified GetDataReader and GetAsyncDataReader methods to return the new unified MiniExcelDataReader.
    • Removed configuration parameter from some GetDataReader and GetAsyncDataReader overloads.
    • Added XML documentation comments to GetDataReader and GetAsyncDataReader methods.
  • src/MiniExcel.Csv/CsvWriter.cs
    • Changed await foreach to foreach when iterating over row in WriteValuesAsync.
  • src/MiniExcel.OpenXml/Api/OpenXmlImporter.cs
    • Removed MiniExcelLib.Core.DataReader using directive.
    • Modified GetDataReader and GetAsyncDataReader methods to return the new unified MiniExcelDataReader.
    • Added XML documentation comments to GetDataReader and GetAsyncDataReader methods.
  • src/MiniExcel.OpenXml/OpenXmlWriter.cs
    • Added cancellationToken parameter to WriteCellAsync method signature and calls.
    • Changed await foreach to foreach when iterating over row in WriteValuesAsync.
    • Passed cancellationToken to writer.WriteAsync calls for EmptyCell and Cell.
  • src/MiniExcel/MiniExcel.cs
    • Updated using directive from MiniExcelLib.Core.DataReader to MiniExcelLib.Core.
    • Adjusted GetReader methods to align with the updated CsvImporter.GetDataReader signatures.
  • tests/MiniExcel.OpenXml.Tests/MiniExcelIssueTests.cs
    • Added TestIssue408 to verify that DataTable.Load can successfully read data from the new MiniExcelDataReader.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors and unifies synchronous and asynchronous data readers into a single MiniExcelDataReader class, improving IDataReader compliance and overall architecture, and enabling direct DataTable loading. A security audit found no vulnerabilities in the analyzed files. However, the review identified potential bugs in the new MiniExcelDataReader implementation and a possible regression in CsvImporter functionality.

- Reintating the CsvConfiguration parameter removed by mistake from the GeDataReader methods in the CsvImporter
- Removing superfluous preprocessor instruction in IMiniExcelDataReader interface
- Adding checks for empty data source and for correct buffering of char array in the MiniExcelDataReader class
- Fixing test 408
@michelebastione
Copy link
Contributor Author

@shps951023 @izanhzh please let me know what you think about these changes.

@shps951023
Copy link
Member

👍👍👍 @michelebastione good day, It looks nice 🙌
and sorry, I'm developing minipdf now, I can't handle miniexcel project at same time.

@michelebastione
Copy link
Contributor Author

@shps951023 Cool! Don't worry about it. Though I do have to mention that in #918 I managed to decouple the core logic from the OpenXml and Csv, which will make it a lot easier if we decide to add support for other formats like Ods in the future. This means that we will need to create a new nuget package for the next prerelease, if you don't have anything against it: MiniExcel.OpenXml.

@shps951023
Copy link
Member

@michelebastione Sounds good! Please go ahead 🙌

@michelebastione michelebastione merged commit 7a0b97f into mini-software:master Mar 3, 2026
3 checks passed
@michelebastione michelebastione deleted the datareader-implementation branch March 3, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getreader报错, Depth,Isclosed,RecordsAffected方法未实现

3 participants