1

I am using this question to convert Excel data to CSV.

   static void ConvertExcelToCsv(string excelFilePath, string csvOutputFile, int worksheetNumber = 1) 
    {
   var cnnStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;IMEX=1;HDR=NO\"", excelFilePath);
   var cnn = new OleDbConnection(cnnStr);
   var dt = new DataTable();
  try {
  cnn.Open();
       }   
     }

I am getting the following exception once the cnn.open() line gets executed:

"External table is not in expected format"

Community
  • 1
  • 1
Code's
  • 208
  • 2
  • 18
  • This code is trying to connect specifically to an Excel 8.0 spreadsheet. What format is the spreadsheet you're connecting to in? – Octopoid Feb 14 '15 at 16:47
  • i am trying to convert excel 2010 to csv – Code's Feb 14 '15 at 17:09
  • You need to change `Excel 8.0` to `Excel 14.0` in your `cnnStr`. Note if you're loading an `xlsx` rather than a `xls` file you'll need `Excel 14.0 Xml` instead. – Octopoid Feb 14 '15 at 17:11
  • When i changed the cnnStr with Excel 14.0 - it says Excel 14.0 is not registered on local machine – Code's Feb 14 '15 at 17:16
  • You'll need to install [this package](http://www.microsoft.com/en-us/download/details.aspx?id=23734). I know it says it's for Office 2007, but it covers 2010 as well. – Octopoid Feb 14 '15 at 17:18

2 Answers2

0

The question in the link is old and using Excel 8.0 Spreadsheet version as Octopoid stated. You can try with the version 12.0 or figure out which version you use :

var cnnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'");



If you can't manage to make it work, you can always use a library :>

Library is called "excellibrary"
Here is the link : https://code.google.com/p/excellibrary/

It is pretty simple to use it. It has a Wiki in the given link so you can get familiar with the usage.

Oğuzhan

Oguzhan D.
  • 169
  • 1
  • 2
  • 15
-1

Heyho, you can open the .xls file and save it as .csv with C#

Michael
  • 50
  • 6