-1

I am looking for a way to import csv files with schma (.ini file). I want import the csv into a datatable. I don't want to use excel interop, because of known issues in running it on windows services.

Is there a way to do so in another tool or technology such as OpenXML?

I've already tested Aspose's and Syncfusion's tools - and it seems they can't offer a solution here. Would appreciate any help.

omer schleifer
  • 3,807
  • 5
  • 28
  • 40

1 Answers1

1

You can do this with an ODBC connection, which treats the text file as a database. Just make sure the .ini file is in the same location as the text-file.

Recording a macro in Excel from the following steps will give you some base code to work with.

  • Data > Import External Data > New Database Query
    1. Select In Create New Data Source,
    2. choose a name
    3. select the driver - Microsoft Text Driver (*.txt, *.csv)
    4. click Connect and in ODBC Text Setup select the folder containing the csv file
    5. select a default table - the csv file (optional)

A similar process can be coded in C# without using Interop. It just uses a database connection, probably OleDbConnection.

Andy G
  • 18,826
  • 5
  • 45
  • 66