Convert XLSM to CSV using Python

Excel to CSV
Convert XLSM to CSV | convert excel to csv online

XLSM is a macro-enabled spreadsheet containing cells arranged by rows and columns as well as embedded macros programmed in the Visual Basic for Applications (VBA) language. XLSM doesn’t take up as much disc space as XLSX and uses an open file format that can be used with many other applications. Whereas a CSV (comma-separated values) file is a text file in which information is separated by commas, and CSV files are most commonly encountered in spreadsheets and databases. Therefore, in this article, we are going to discuss the details of how to convert XLSM to CSV using Python.

Excel Conversion API

Aspose.Cells Cloud provides the option to create, edit and convert Excel worksheets to CSV and other supported formats. When considering implementing the conversion operations in Python application, Aspose.Cells Cloud SDK for Python is a choice. Now please execute the following command to install the SDK:

pip install asposecellscloud

After installation, please register a free account over Aspose.Cloud dashboard using GitHub or Google account or use Sign Up to obtain your Client Credentials.

Convert XLSM to CSV in Python

Please follow the instructions specified below to convert XLSM to CSV using a Python code snippet. Please note that first, we are going to upload the XLSM to cloud storage, load the XLSM from the same cloud storage, and render the output in CSV format.

  • Create an object of CellsApi using client credentials
  • Now specify the name of input XLSM, resultant file name, and output format as CSV
  • Call cells_workbook_get_workbook(…) method to convert XLSM to CSV format and save the output to Cloud storage

Excel to CSV using cURL Commands

In this section, lets dsicuss the convesion of Excel to CSV using cURL commands. The pre-requisite is creation of JWT access token using following command:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now that we have the JWT token, lets execute the following command to convert XLSM to CSV and save the resultant output in cloud storage.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/myDocument.xlsm?format=CSV&isAutoFit=false&onlySaveTable=false&outPath=Converted.csv&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"
Excel to CSV
Image 1:- Excel to CSV conversion preview

In above image, you may notice that all the textual information from all worksheets is extracted to single CSV file. For your reference, we have also attached the sample files

Conclusion

In this article, we have learned about the steps on how to convert XLSM to CSV using REST API. We have explored the options to convert Excel to CSV using Python code snippet as well as using cURL Commands. Please note that under MIT license, we have published our Cloud SDKs and you can download them from GitHub and can even modify source code as per your requirements. You may consider exploring the Developer Guide to learn about other exciting features being offered by the API. In case you encounter any issues, please feel free to contact us via the free technical support forum.

Related Articles

We recommend going through the following articles for further understanding: