Excel to CSV

How to convert Excel to CSV online

XLSM files are similar to XLM file formats but are based on the Open XML format and support macros. On the other end, CSV is a more viable option because CSV is human readable, CSV format is dictated by a straightforward schema, and CSV files can be read using almost any text editor. Also, the CSV can be used to directly import data inside various applications without making any modifications to the input file. In this article, we are going to explore the details of how to convert XLSM to CSV.

Excel to CSV Conversion API

Aspose.Cells Cloud is specifically developed to empower developers to modify or convert Microsoft Excel & OpenOffice spreadsheets in the cloud, without any software dependencies. Now in order to get started using .NET SDK, the first step is its installation, and it’s available for download at NuGet and GitHub. Please execute the following command in the terminal window to perform the installation for NuGet:

nuget install Aspose.Cells-Cloud

In case you are using .NET CLI, please execute the following command:

dotnet add package Aspose.Cells-Cloud

Package Manager Console

If you are using Visual Studio, then the package can also be installed using the Package Manager Console. Please execute the following command:

PM> Install-Package Aspose.Cells-Cloud

Now we need to create a free account on Aspose.Cloud dashboard where we can use existing GitHub or Google accounts or click the Create a new Account button and obtain Client Credentials.

XLSM to CSV in C#

Please follow the instructions specified below to perform the conversion operations using the C# .NET code snippet.

  • The first step is to create an instance of CellsApi while passing ClientID and ClientSecret details as arguments
  • Secondly, define the input file, resultant file name, and format of the resultant file
  • Thirdly, load the XLSB to File.OpenRead instance
  • The next step is to initialize the conversion operation using CellsWorksheetsGetWorksheet(…) method
  • Finally, use File.Create an instance to save the output on the system drive (as specified in saveToDisk(…) method)
Excel to CSV preview

Image 4:- XLSM to CSV conversion preview.

Convert Excel to CSV using cURL Commands

Aspose.Cells Cloud is developed as per REST architecture, therefore, it can easily be accessed on any platform using the cURL commands. However, in order to ensure the privacy aspect, we need to first generate a JWT access token based on Client ID and Client Secret specified over Aspose.Cloud dashboard. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

The easiest approach for conversion is through PostDocumentSaveAs API. Simply provide the input file name and resultant file name and with a single command, the job is completed. However, in this approach, the first worksheet of the XLSM workbook is converted to CSV format.

curl -v -X POST "https://api.aspose.cloud/v3.0/cells/TestCase.xlsm/SaveAs?newfilename=TestCase.csv&isAutoFitColumns=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{}"

Another approach is the usage of GetWorkBook API to perform the conversion operation. Provide input XLSM available in cloud storage through name parameter, the CSV value is provided against format parameter and resultant file is provided against outPath parameter.

curl -X GET "https://api.aspose.cloud/v3.0/cells/TestCase.xlsm?format=CSV&isAutoFit=false&onlySaveTable=false&outPath=Converted.csv" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

The response body will have the following output

{
  "FileInfo": {
    "Name": "Converted.csv",
    "Size": 71
  },
  "Code": 200,
  "Status": "OK"
}

Convert XLSM in Request Parameter

In case you need to perform the conversion of the XLSM file from your local drive, then upload it using Request instance and use PutConvertWorkBook API. Please use the following command to perform the conversion.

curl -X PUT "https://api.aspose.cloud/v3.0/cells/convert?format=CSV&outPath=Converted.csv" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"File":{}}

Convert specific Worksheet to CSV

In case you need to convert a specific worksheet to CSV format, please try using GetWorkSheetWithFormat API and provide the name of the worksheet against a sheetName parameter. In case we do not provide the -o parameter, the values of the worksheet are displayed in the console.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/TestCase.xlsm/worksheets/Sheet2?format=CSV&verticalResolution=0&horizontalResolution=0" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o Resultant.csv
XLSX to CSV Conversion Preview

Image 5:- Preview of output in the console if the output file parameter is not provided.

Conclusion

In this article, we have discussed the details of how to convert XLSM to CSV. The conversion steps have been explained for .NET Cloud SDK as well as we have learned how we can convert excel to CSV using the cURL command. Please note that our SDKs are open source and have an MIT license. You can use them, and even customize them absolutely free of charge. The complete source code is available on GitHub.

Last but not least, the Cloud API can also be accessed through the Swagger interface within a web browser.

We recommend visiting the following links to learn more about