Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DatabaseEngine: Jet, Ace2010, Ace2013, Ace2016 #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ Checkout the [introduction video.](http://www.youtube.com/watch?v=t3BEUP0OTFM)
You can use NuGet to quickly add LinqToExcel to your project. Just search for `linqtoexcel` and install the package.

#### Access Database Engine
In order to use LinqToExcel, you need to install the Microsoft [Microsoft Access Database Engine 2010 Redistributable](https://www.microsoft.com/en-in/download/details.aspx?id=13255). If it's not installed, you'll get the following exception:
In order to use LinqToExcel, you need to install either of the [Microsoft Access Database Engine 2010 Redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=13255), [Microsoft Access 2013 Runtime](https://www.microsoft.com/en-us/download/details.aspx?id=39358), [Microsoft Access 2016 Runtime](https://www.microsoft.com/en-us/download/details.aspx?id=50040). If it's not installed, you'll get the following exception:

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.'
The 'Microsoft.ACE.OLEDB.15.0' provider is not registered on the local machine.'
The 'Microsoft.ACE.OLEDB.16.0' provider is not registered on the local machine.'

*Both a 32-bit and 64-bit version are available, select the one that matches your project settings.* You can only have one of them installed at a time.

Expand Down
15 changes: 15 additions & 0 deletions src/LinqToExcel/Domain/DatabaseEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqToExcel.Domain
{
public enum DatabaseEngine
{
Jet,
Ace2010,
Ace2013,
Ace2016
}
}
25 changes: 17 additions & 8 deletions src/LinqToExcel/ExcelQueryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public ExcelQueryFactory(string fileName)
public ExcelQueryFactory(string fileName, ILogManagerFactory logManagerFactory)
{
FileName = fileName;
DatabaseEngine = ExcelUtilities.DefaultDatabaseEngine();
OleDbServices = OleDbServices.AllServices;

if (logManagerFactory != null) {
Expand All @@ -95,15 +96,22 @@ public ExcelQueryFactory(string fileName, ILogManagerFactory logManagerFactory)
}
}

#region Other Methods

/// <summary>
/// Add a column to property mapping
/// Sets the database engine to use
/// (Spreadsheets ending in xlsx, xlsm, and xlsb must use the Ace database engine)
/// (If running 64 bit this defaults to ACE (JET doesn't work anyway), if running 32 bit this detaults to JET)
/// </summary>
/// <typeparam name="TSheetData">Class type to return row data as</typeparam>
/// <param name="property">Class property to map to</param>
/// <param name="column">Worksheet column name to map from</param>
public void AddMapping<TSheetData>(Expression<Func<TSheetData, object>> property, string column)
public DatabaseEngine DatabaseEngine { get; set; }

#region Other Methods

/// <summary>
/// Add a column to property mapping
/// </summary>
/// <typeparam name="TSheetData">Class type to return row data as</typeparam>
/// <param name="property">Class property to map to</param>
/// <param name="column">Worksheet column name to map from</param>
public void AddMapping<TSheetData>(Expression<Func<TSheetData, object>> property, string column)
{
AddMapping(GetPropertyName(property), column);
}
Expand Down Expand Up @@ -224,7 +232,8 @@ internal ExcelQueryConstructorArgs GetConstructorArgs()
return new ExcelQueryConstructorArgs()
{
FileName = FileName,
StrictMapping = StrictMapping,
DatabaseEngine = DatabaseEngine,
StrictMapping = StrictMapping,
ColumnMappings = _columnMappings,
Transformations = _transformations,
UsePersistentConnection = UsePersistentConnection,
Expand Down
7 changes: 6 additions & 1 deletion src/LinqToExcel/IExcelQueryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,10 @@ public interface IExcelQueryFactory : IDisposable
/// </summary>
/// <param name="worksheetName">Worksheet name to get the list of column names from</param>
IEnumerable<string> GetColumnNames(string worksheetName);
}

/// <summary>
/// Sets the database engine to use (spreadsheets ending in xlsx, xlsm, xlsb will always use the Ace engine)
/// </summary>
DatabaseEngine DatabaseEngine { get; set; }
}
}
11 changes: 7 additions & 4 deletions src/LinqToExcel/Query/ExcelQueryArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace LinqToExcel.Query
internal class ExcelQueryArgs
{
internal string FileName { get; set; }
internal string WorksheetName { get; set; }
internal DatabaseEngine DatabaseEngine { get; set; }
internal string WorksheetName { get; set; }
internal int? WorksheetIndex { get; set; }
internal Dictionary<string, string> ColumnMappings { get; set; }
internal Dictionary<string, Func<string, object>> Transformations { get; private set; }
Expand All @@ -28,7 +29,7 @@ internal class ExcelQueryArgs
internal int CodePageIdentifier { get; set; }

internal ExcelQueryArgs()
: this(new ExcelQueryConstructorArgs())
: this(new ExcelQueryConstructorArgs() { DatabaseEngine = ExcelUtilities.DefaultDatabaseEngine() })
{
OleDbServices = OleDbServices.AllServices;
}
Expand All @@ -41,7 +42,8 @@ internal ExcelQueryArgs(ExcelQueryArgs orig) : this()
if (orig != null)
{
FileName = orig.FileName;
WorksheetName = orig.WorksheetName;
DatabaseEngine = orig.DatabaseEngine;
WorksheetName = orig.WorksheetName;
WorksheetIndex = orig.WorksheetIndex;
ColumnMappings = orig.ColumnMappings;
Transformations = orig.Transformations;
Expand All @@ -62,7 +64,8 @@ internal ExcelQueryArgs(ExcelQueryArgs orig) : this()
internal ExcelQueryArgs(ExcelQueryConstructorArgs args)
{
FileName = args.FileName;
ColumnMappings = args.ColumnMappings ?? new Dictionary<string, string>();
DatabaseEngine = args.DatabaseEngine;
ColumnMappings = args.ColumnMappings ?? new Dictionary<string, string>();
Transformations = args.Transformations ?? new Dictionary<string, Func<string, object>>();
StrictMapping = args.StrictMapping ?? StrictMappingType.None;
UsePersistentConnection = args.UsePersistentConnection;
Expand Down
3 changes: 2 additions & 1 deletion src/LinqToExcel/Query/ExcelQueryConstructorArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public ExcelQueryConstructorArgs()
}

internal string FileName { get; set; }
internal Dictionary<string, string> ColumnMappings { get; set; }
internal DatabaseEngine DatabaseEngine { get; set; }
internal Dictionary<string, string> ColumnMappings { get; set; }
internal Dictionary<string, Func<string, object>> Transformations { get; set; }
internal StrictMappingType? StrictMapping { get; set; }
internal bool UsePersistentConnection { get; set; }
Expand Down
Loading