Click here to Skip to main content
12,630,420 members (29,736 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked

How to Convert Excel to CSV using Interop

, 19 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This simple Tip will give you the Trick to convert Excel file to CSV file using Interop Services.


At times, you might need to convert one Excel file to CSV. If you want to do this using Microsoft's Interop Services, then follow this Tip.


This little piece of code is a result of the research during development of one Windows Utility, which uploads Excel sheets to database.

Using the code 

First of all, we will check if Excel is installed on the system or not, as Interop works only when Excel is installed on the system. Follow my previous Tip -  How to Check Whether Excel is Installed in the System or Not

To save the file as CSV, we will use Workbook.SaveAs Method

Saves changes to the workbook in a different file. 
Type officeType = Type.GetTypeFromProgID("Excel.Application");

if (officeType == null)
    // Excel is not installed.
    // Show message or alert that Excel is not installed.
    // Excel is installed.
    // Let us continue our work on Excel file conversion. 
    Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

    // While saving, it asks for the user confirmation, whether we want to save or not.
    // By setting DisplayAlerts to false, we just skip this alert.
    app.DisplayAlerts = false;

    // Now we open the upload file in Excel Workbook. 
    Microsoft.Office.Interop.Excel.Workbook excelWorkbook = app.Workbooks.Open(openFileDialog.FileName);

    string newFileName = System.IO.Directory.GetCurrentDirectory() + "\\DataMigration.csv";

    // Now save this file as CSV file.
    excelWorkbook.SaveAs(newFileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV);
    // Close the Workbook and Quit the Excel Application at the end. 

So, the Excel file is now saved as CSV file inside the Current Directory of the Project. 


  • 18 November 2013 - First version submitted for approval 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Software Developer Mindfire Solutions
India India
Official Facebook Page - Tadit Dash

Proud Indian | Microsoft MVP | CodeProject MVP | Speaker | Author | DZone Most Valuable Blogger | Community Expert | Moderator | jsfiddler | Cook | Dancer

Currently working @Mindfire Solutions.
Love to code and help guys to Trap the Bug.

My Tech Blog

Programming Community Profiles

jsfiddle | Stack Overflow

Other Blog Profiles

Mindfire CRM Team Blog | Mindfire Blog

Social Profiles

Facebook | Twitter | LinkedIn | Google+


  1. DZone Most Valuable Blogger
  2. Microsoft MVP 2014, 2015, 2016
  3. Code Project MVP 2014, 2015, 2016
  4. Star Achiever of the Month December 2013
  5. Mindfire Techno Idea Contest 2013 Winner
  6. Star of the Month July 2013

You may also be interested in...


Comments and Discussions

Questionboth case not installed? Pin
Andrea Feduzzi19-Nov-13 3:08
memberAndrea Feduzzi19-Nov-13 3:08 
AnswerRe: both case not installed? Pin
Tadit Dash19-Nov-13 5:10
professionalTadit Dash19-Nov-13 5:10 
GeneralRe: both case not installed? Pin
Andrea Feduzzi19-Nov-13 5:43
memberAndrea Feduzzi19-Nov-13 5:43 
GeneralRe: both case not installed? Pin
Tadit Dash19-Nov-13 5:55
professionalTadit Dash19-Nov-13 5:55 
Yeah, absolutely correct. Poke tongue | ;-P

GeneralVery Elegant Pin
Manoj Ningwani18-Nov-13 5:15
professionalManoj Ningwani18-Nov-13 5:15 
GeneralRe: Very Elegant Pin
Tadit Dash18-Nov-13 6:23
professionalTadit Dash18-Nov-13 6:23 
GeneralRe: Very Elegant Pin
Aaron Sulwer25-Jul-14 11:11
memberAaron Sulwer25-Jul-14 11:11 
GeneralRe: Very Elegant Pin
Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)29-Jul-14 1:27
protectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)29-Jul-14 1:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 19 Nov 2013
Article Copyright 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid