Click here to Skip to main content
Click here to Skip to main content

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
NOW I am a Conference Speaker. Please invite me to your College, Company, Event or Conference !!!
Proud Indian | Microsoft MVP | CodeProject MVP | Author | DZone Most Valuable Blogger | Community Expert | Moderator | jsfiddler | Cricketer | 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
  3. Code Project MVP 2014
  4. Star Achiever of the Month December 2013
  5. Mindfire Techno Idea Contest 2013 Winner
  6. Star of the Month July 2013
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

GeneralMy vote of 5 PinprofessionalSibeesh KV13-Nov-14 18:55 
GeneralRe: My vote of 5 PinprotectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)17-Nov-14 4:02 
GeneralRe: My vote of 5 PinprofessionalSibeesh KV17-Nov-14 5:27 
QuestionSee also this: PinprofessionalDietmar Schoder29-Jul-14 6:22 
AnswerRe: See also this: PinprotectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)29-Jul-14 7:42 
GeneralMy vote of 1 PinmemberAaron Sulwer25-Jul-14 11:12 
GeneralRe: My vote of 1 PinprotectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)29-Jul-14 1:25 
QuestionThis method does not work on my computer with Visual C# Express 2010 and Excel 2010 Pinmembermegreen19-Dec-13 11:05 
AnswerRe: This method does not work on my computer with Visual C# Express 2010 and Excel 2010 PinmvpTadit Dash6-Jan-14 18:57 
Questionboth case not installed? PinmemberAndrea Feduzzi19-Nov-13 3:08 
AnswerRe: both case not installed? PinprofessionalTadit Dash19-Nov-13 5:10 
GeneralRe: both case not installed? PinmemberAndrea Feduzzi19-Nov-13 5:43 
GeneralRe: both case not installed? PinprofessionalTadit Dash19-Nov-13 5:55 
GeneralVery Elegant PinprofessionalManoj Ningwani18-Nov-13 5:15 
GeneralRe: Very Elegant PinprofessionalTadit Dash18-Nov-13 6:23 
Thanks a lot Manoj... Cool | :cool: Smile | :) Thumbs Up | :thumbsup:

GeneralRe: Very Elegant PinmemberAaron Sulwer25-Jul-14 11:11 
GeneralRe: Very Elegant PinprotectorTadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)29-Jul-14 1:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.150224.1 | Last Updated 19 Nov 2013
Article Copyright 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid