Book Online or Call 1-855-SAUSALITO

Sign In  |  Register  |  About Sausalito  |  Contact Us

Sausalito, CA
September 01, 2020 1:41pm
7-Day Forecast | Traffic
  • Search Hotels in Sausalito

  • CHECK-IN:
  • CHECK-OUT:
  • ROOMS:

How to write CSV in .NET

How to write CSV in .NETPhoto by Danial Igdery

Originally Posted On: Csharp Write to CSV File | IronXL (ironsoftware.com)

 

Ever wondered how to quickly use C# to write to CSV? Wonder no more! IronXL provides a very quick and easy way to write data into CSV files in .NET.

Code Examples

 Save as CSV FileVB 

 C#

  1. private void button3_Click(object sender, EventArgs e)
  2. {
  3. WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); //Import .xls, .csv, or .tsv file
  4. wb.SaveAs("Excel_To_CSV.csv"); //Exported as : Excel_To_CSV.Sheet1.csv
  5. }
   Copy code to clipboardJump to Article 

Try IronXL free for development  Download Free

How to write CSV in .NET

 


 

Step 11. Add IronXL to Your Project

Just in case you haven’t installed IronXL yet, here’s the quick steps you need to take

  • Open Visual Studio and select the Project menu
  • Click Manage NuGet Packages
  • Search for IronXL.Excel
  • Click Install

Or use the following command into the Developer Command Prompt:

PM> Install-Package IronPdf

Or you can download directly from the Iron Software website, here: https://ironsoftware.com/csharp/excel/docs/

 


 

How to Tutorial2. Create an Excel Workbook

Let’s create a quick project!

First, create an Excel workbook containing the following information

 

Normal Excel data to be exported to CSV

Figure 1 – Normal Excel data to be exported to CSV

Then add the IronXL Namespace in order to be able to write to csv files in C# and IronXL

  1. using IronXL;

   Copy code to clipboardVB 

 C#

 


 

2. Save Workbook to CSV

The following code makes use of the Workbook object’s Load method to load a file into Excel.

Then, it uses the SaveAs method to save the file in the desired format – in this case: CSV.

What’s interesting here is that it appends the name of the worksheet onto the filename, which is a quite nifty reminder on where the data is coming from.

  1. private void button3_Click(object sender, EventArgs e)
  2. {
  3. WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); //Import .xls, .csv, or .tsv file
  4. wb.SaveAs("Excel_To_CSV.csv"); //Exported as : Excel_To_CSV.Sheet1.csv
  5. }

   Copy code to clipboardVB 

 C#

The output CSV file looks like the following when opened in a normal Text Editor such as Notepad.

 

Output CSV file

Figure 2 – Output CSV file

 

Data & News supplied by www.cloudquote.io
Stock quotes supplied by Barchart
Quotes delayed at least 20 minutes.
By accessing this page, you agree to the following
Privacy Policy and Terms and Conditions.
 
 
Photos copyright by Jay Graham Photographer
Copyright © 2010-2020 Sausalito.com & California Media Partners, LLC. All rights reserved.