Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:37:08+00:00 2026-05-23T21:37:08+00:00

In my application i can import csv file but i have data in excel

  • 0

In my application i can import csv file but i have data in excel sheet so i need to convert it to csv format.
i got code from net for exporting excel data to csv when i downloaded zip file of it and run that its working but its not working when i copy this program to vs 2008 and run it

The code is

using System;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;

namespace XlsToCsv
{
    class Program
    {
        static void Main(string[] args)
        {
            string sourceFile, worksheetName, targetFile;
            sourceFile = @"D:\emp.xls";worksheetName = "sheet1"; targetFile = @"D:\empcsv.csv";
            convertExcelToCSV(sourceFile, worksheetName, targetFile);
        }

        static void convertExcelToCSV(string sourceFile, string worksheetName, string targetFile)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sourceFile + ";Extended Properties=\" Excel.0;HDR=Yes;IMEX=1\""; 
            OleDbConnection conn = null;
            StreamWriter wrtr = null;
            OleDbCommand cmd = null;
            OleDbDataAdapter da = null; 
            try
            {
                conn = new OleDbConnection(strConn);
                conn.Open();

                cmd = new OleDbCommand("SELECT * FROM [" + worksheetName + "$]", conn);
                cmd.CommandType = CommandType.Text;
                wrtr = new StreamWriter(targetFile);

                da = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);

                for (int x = 0; x < dt.Rows.Count; x++)
                {
                    string rowString = "";
                    for (int y = 0; y < dt.Columns.Count; y++)
                    {
                        rowString += "\"" + dt.Rows[x][y].ToString() + "\",";
                    }
                    wrtr.WriteLine(rowString);
                }
                Console.WriteLine();
                Console.WriteLine("Done! Your " + sourceFile + " has been converted into " + targetFile + ".");
                Console.WriteLine();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.ToString());
                Console.ReadLine();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
                conn.Dispose();
                cmd.Dispose();
                da.Dispose();
                wrtr.Close();
                wrtr.Dispose();
            }
        }
    }
}

its throwing error like this

System.Data.OleDb.OleDbException: Could not find installable ISAM.

   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString cons
tr, OleDbConnection connection)

   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOpti
ons options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection o
wningObject)

   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbC
onnection owningConnection, DbConnectionPoolGroup poolGroup)

   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)

   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)

   at System.Data.OleDb.OleDbConnection.Open()

   at Excel_To_csv.Program.convertExcelToCSV(String sourceFile, String worksheet
Name, String targetFile) in D:\Excel to csv\Excel To csv\Excel To csv\Program.cs
:line 41

why is this error coming i dont know

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:37:09+00:00Added an answer on May 23, 2026 at 9:37 pm

    your error may be arising because of excel driver issues im not 100% sure about that however this error arising because of some required dll’s are missing form you computer.

    you might be able to solve this issue by installing MDAC to your computer and try to execute this.

    if it’s not solved you can use the below pasted code which is written by me just as a answer to your question but first of all i should tell you this below code part is not efficient if the conversion file has quite considerable number of record’s ex 65000

    To use the below code part you need to add below reference

    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
    

    Function

     private void EXCELTOCSV()
        {
            OpenFileDialog excelSheetToOpen = new OpenFileDialog();
            excelSheetToOpen.Filter = "Excel 97- 2003 WorkBook (*.xls)| *.xls | Excel 2007 WorkBook (*.xlsx) | *.xlsx | All files (*.*)|*.*";
            excelSheetToOpen.FilterIndex = 3;
            excelSheetToOpen.Multiselect = false;
    
    
    
            if (excelSheetToOpen.ShowDialog() == DialogResult.OK)
            {
    
                Excel.Application excelApp = new Excel.Application();
                String workbookPath = excelSheetToOpen.FileName;
                Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath);
                Excel.Sheets excelWorkBookSheets = excelWorkbook.Sheets;
    
                Excel.Range _UsedRangeOftheWorkSheet;
    
    
                foreach (Excel.Worksheet _Sheet in excelWorkBookSheets)
                {
                    if (_Sheet.Name =="ExcelSheetName")
                    {
    
                        _UsedRangeOftheWorkSheet = _Sheet.UsedRange;
    
                        Object[,] s = _UsedRangeOftheWorkSheet.Value;
    
                        System.IO.StreamWriter sw = new System.IO.StreamWriter("FileName.csv", true);
    
                        for (int b = 0; b < s.Length; b++)
                        {
                            StringBuilder sb = new StringBuilder();
                            for (int c = 0; c < s.Rank; c++)
                            {
                                if (sb == null)
                                {
                                    sb.Append((String)s[b, c]);
                                }
                                else
                                {
                                    sb.Append("," + (String)s[b, c]);
                                }
                            }
                            sw.WriteLine(sb.ToString());
                        }
                        sw.Close();
    
                    }
                }
    
            }
        }
    

    Hope this will work for you

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that can import an XML file through this terminal command
i need to import some bulk data in an asp.net application from txt/csv files
I have a VB application which extracts data and creates 3 CSV files (a.csv,
I have an Excel file (which has data imported from Oracle 10G Database) one
I have a custom class loader so that a desktop application can dynamically start
I'm trying to consume a webmethod but it seems that my application can't resolve
I have a Windows Forms (.NET) application that can have multiple documents open simultaneously.
I have a delphi (Win32) web application that can run either as a CGI
I have a C++ Windows application that can be extended by writing C++ plugins,
For part of a web application the user needs to import some data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.