XLSM to CSV – Convert XLSM to CSV in C#


XLSM files are similar to XLM file formats but are based on the Open XML format and it was introduced in Microsoft Office 2007. In other words, XLSM is XLSX files but with the support of macros. From the application point of view, a Macro is a set of instructions that are used for automating processes. However, from an information-sharing perspective, the recipient might only be interested in the content present in a file rather than macros. So 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. Furthermore, the CSV can be used to directly import data inside various applications without making any modifications to the input file.

Excel Manipulation API

Aspose.Cells Cloud is specifically developed to empower developers to modify or convert Microsoft Excel & OpenOffice spreadsheets in the cloud, without any installation. No additional software installation or download is required. You can perform the Excel processing operations even without MS Office automation.

In this article, we are going to focus on Aspose.Cells Cloud SDK for .NET which is a wrapper around REST API. So get started using the 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 Package Manager Console. Please execute the following command:

PM> Install-Package Aspose.Cells-Cloud
Aspose.Cells Package
Image 1:- Aspose.Cells NuGet package installed.

NuGet Package Manager – Visual Studio

Another easiest approach is to install the SDK via NuGet Package Manager within Visual Studio IDE.

  1. Open the Solution Explorer.
  2. Expand the project and Right-click Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Cells-Cloud
  5. Click on the Aspose.Cells-Cloud package, select the appropriate version in the right-tab and click Add Package button
Aspose.Cells NuGet package
Image 2:- Aspose.Cells Package in NuGet Package Manager.

Cloud Dashboard

Aspose.Cloud dashboard enables you to manage your account subscription. It also provides you a web interface to access files available in Cloud storage. So in order to ensure data integrity and security, you need to subscribe to a Free account on Aspose.Cloud dashboard. During subscription, no credit card or payment details are required and you can perform up to 150 free document processing operations. And once you are satisfied with the capabilities of API, you may consider opting for a license subscription which can be as low as $0.005 / API call. For further details, please visit Pricing.

Now let’s proceed with account subscription. So if you have GitHub or Google account, simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials
Image 3:- Client Credentials at Aspose.Cloud dashboard.

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 input file, resultant file name and format of 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 instance to save the output on system drive (as specified in saveToDisk(…) method)
Image 4:- XLSM to CSV conversion preview.

Convert XLSM to CSV using cURL

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
Image 5:- Preview of output in the console if the output file parameter is not provided.


In this article, we have discussed the details on how to perform spreadsheet files supporting Macros (XLSM) to Comma Separated Files (CSV). The conversion steps have been explained for .NET Cloud SDK as well as how the same operation can be performed using the cURL command. Furthermore, 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 over GitHub. While using the API, if you encounter any issues or you have any further queries, please feel free to contact us through the free customer support forum.

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

Related Articles

We recommend visiting the following links to learn more about