excel to csv

Convert Excel (XLS, XSLX) to CSV using C# .NET

Excel spreadsheets are an essential tool for storing, managing and analyzing data. However, there may be times when you need to convert your Excel data into another format, such as CSV, to make it more accessible to others or to import it into another application. The good news is that converting Excel to CSV has never been easier, but thanks to Aspose.Cells Cloud. It’s a powerful cloud-based API which provides the ability to convert Excel data into various file formats, including CSV, with just a few lines of code. In this article, we’ll show you how to use Aspose.Cells Cloud to convert Excel spreadsheets into CSV format, and explore the benefits of using this powerful API for your data conversion needs.

Excel to CSV Conversion API

Learn how to simplify the process of converting Excel data into CSV format with the help of Aspose.Cells Cloud. This API supports the latest versions of Excel and provides a comprehensive set of features that make it easy to convert data between different file formats. Similarly, Aspose.Cells Cloud SDK for .NET provides a simple and straightforward way to convert Excel to CSV using C# programming language (using few code lines). So, whether you are a beginner or an experienced developer, this article will help you get started with Excel to CSV conversion using Aspose.Cells Cloud SDK for .NET.

To get started with SDK utilization, we need to add its reference through NuGet package manager. Simply search “Aspose.Cells-Cloud” and hit the Add Package button.

Now, in order to use the API capabilities, we also need to have a Cloud dashboard account. If you are not already subscribed, please create a free account over Cloud Dashboard using valid email address and obtain your personalized client credentials.

Convert Excel to CSV using C#

Given below is the code snippet which can help us to convert Excel to CSV without using Microsoft Office Automation or any other utility installed. As you may observe, the whole process is simple and straight forward.

Let’s understand the above code snippet:

CellsApi instance = new CellsApi(clientID, clientSecret);

Create an object of CellsApi where we pass the client credentials as arguments.

var file = System.IO.File.OpenRead(name)

Read the input Excel worksheet using OpenRead(…) method of the System.IO.File class.

CellsWorkbookPutConvertWorkbook(file, format: format, outPath: resultantFile);  

This method triggers the Excel to CSV conversion operation and saves the resultant CSV in Cloud storage.

using (var fileStream = new FileStream("myResultant.csv", System.IO.FileMode.OpenOrCreate, FileAccess.Write))

Use this code to save the resultant CSV to local drive.

excel to csv

Image 2:- XLSX to CSV conversion preview.

Use the following link to download the sample Excel worksheet TestCase.xlsx used in the above example.

XLSX to CSV using cURL Commands

There are several reasons why accessing Aspose.Cells Cloud via cURL commands is a great option for developers. Some of the benefits of using cURL commands include:

  1. Automation: Automate the conversion process, making it easier and more efficient.
  2. Cross-platform compatibility: Supported on Windows, macOS, and Linux, making it an ideal option for developers working with a variety of operating systems.
  3. Easy to integrate: Integrate with other tools and systems (incorporate into existing workflows).
  4. Flexibility: Allowing you to specify the format and structure of the output.
  5. Improved security: you can ensure that the sensitive data remains secure, as the process does not involve sending data to a third-party website or application.

Now, the first step in the conversion process is to generate a JWT access token based on our client credentials:

curl -v "https://api.aspose.cloud/connect/token" \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

After token generation, please execute the following command to convert the XLSX to CSV and save the output to Cloud storage:

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/TestCase(1).xlsx?format=CSV&isAutoFit=false&onlySaveTable=false&outPath=output.csv&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

In case we are interested to save the exported CSV to local drive, please try using the following cURL command:

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/TestCase(1).xlsx?format=CSV&isAutoFit=false&onlySaveTable=false&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o  "output.csv"

Concluding Remarks

By the end of this article, we have concluded that Aspose.Cells Cloud provides a convenient and reliable way to convert Excel spreadsheets to CSV format using C# programming language. Furthermore, this API offers a wide range of features and functionalities, making it an ideal solution for developers and businesses who need to convert Excel data into CSV format. Whether you are looking to automate your data conversion process, or simply want to make the conversion process easier and more efficient, Aspose.Cells Cloud is the perfect solution for you. With its user-friendly interface, comprehensive features, and robust SDK for .NET, you can be sure that you are getting the best possible solution for your data conversion needs. So, if you’re looking for a quick and efficient way to convert Excel to CSV, try using Aspose.Cells Cloud today.

Please don’t skip exploring the Product Documentation, which contains the amazing topics explaining all the exciting features of the API. Lastly, if you encounter any issues while using the API, please feel free to contact us via the free Product Support Forum.

Please visit the following links to learn more about: