Quantcast
Channel: Excel Data Reader - Read Excel files in .NET
Viewing all articles
Browse latest Browse all 448

Commented Unassigned: ExcelCsvReader - CSV reader implementation [13097]

$
0
0
This is my contrib to the Library:

a CSV data reader implementation to extend ExcelReaderFactory.
Comments: ** Comment from web user: wizardgsz **

Hello and thanks for your feedback.

No unit-tests for the class :)

To integrate your framework I think it would be enough to extend ExcelReaderFactory:

```
/// <summary>
/// Creates an instance of <see cref="ExcelCsvReader"/>
/// </summary>
/// <param name="fileStream">The file stream.</param>
/// <returns></returns>
public static IExcelDataReader CreateOpenXmlReader(Stream fileStream)
{
IExcelDataReader reader = new ExcelCsvReader();
reader.Initialize(fileStream);

return reader;
}
```

Just a new property Encoding to my class to handle non-UTF8 (the default encoding) files:

```
private readonly Encoding m_Default_Encoding = Encoding.UTF8;
private Encoding m_encoding;

/// <summary>
/// Gets or sets the encapsuled <see cref="StreamReader"/> <see cref="Encoding"/>.
/// </summary>
/// <value>The used Encoding.</value>
public Encoding Encoding
{
get { return m_encoding; }
set { m_encoding = value; }
}
```

While XLS/XLSX "have/bring" information about encoding, CSV has not such info so you have to specify it to read characters like à, è, ì...

Usage, for example:

```
((Excel.ExcelCsvReader)excelReader).Encoding = Encoding.GetEncoding(1252);
```

Have a nice day


Viewing all articles
Browse latest Browse all 448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>