Excel to text

Convert Excel (XLS, XLSX) to Text file using C# .NET

Excel spreadsheets are a ubiquitous tool for managing and analyzing data. However, they are not always the most efficient format for web applications. Therefore, converting Excel files to text file (.txt) is a common task in data processing, as it allows users to manipulate data in a more flexible and readable format. The text files are also lightweight and easy to open in various programs, making them an ideal choice for storing and sharing data. However, converting Excel files to text file (.txt) format can be a daunting task, especially if you are not familiar with programming languages. Fortunately, with C# .NET, you can easily convert your Excel files to Text format without much effort. In this guide, we will show you how to convert your Excel data to text file (.txt) using .NET Cloud SDK.

Excel to Text Conversion API

Aspose.Cells Cloud SDK for .NET is an efficient and cost-effective way to convert Excel files to text file (.txt) format. This cloud-based approach provides numerous benefits, including scalability, accessibility, and enhanced security features. The conversion process is reliable, and generates high-quality results. Simply search “Aspose.Cells-Cloud” in NuGet packages manager and click the “Add Package” button. Secondly, if you do not have an account over Cloud Dashboard, please create a free account by using a valid email address and obtain your personalized credentials.

Convert Excel to TXT using C#

The API offers the following three methods to deal with file format conversion.

Now in this section, our interest is to load the input Excel file from local drive, perform the conversion and save the resultant Text file in cloud storage.

Let’s develop our understanding regarding this code snippet:

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

Create an object of CellsApi while passing client credentials as arguments.

var file = System.IO.File.OpenRead(input_Excel);

Read the content of input Excel workbook into FileStream object.

var response = cellsInstance.CellsWorkbookPutConvertWorkbook(file, format:"TXT", outPath:resultant_File);

Call API to convert Excel to Text format. The resultant file format and resultant Text file name, are provided as argument to this method. After the conversion, the output is saved in cloud storage.

Excel to Text

Excel to text conversion preview.

The input Excel workbook and the resultant TXT file generated in the above example can be downloaded from input.xls and output.txt.

Excel to Text File using cURL Commands

We have learned that text files are lightweight and efficient to transmit over the internet. Now, in this section, we are going to convert Excel files to text format using Aspose.Cells Cloud REST API and cURL command. This approach provides multiple benefits, such as compatibility with various software applications and operating systems, improved data security, and increased efficiency.

So in order to get started, we need to generate a JWT access token based on client credentials:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-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"

The next step is to call the API PostWorkbookSaveAs. This API loads the input Excel from cloud storage and then, saves the resultant TXT to the same cloud storage.

curl -v -X POST "https://api.aspose.cloud/v3.0/cells/myDocument(2).xlsx/SaveAs?newfilename=converted.txt&isAutoFitRows=false&isAutoFitColumns=false&checkExcelRestriction=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"SaveFormat\": \"TXT\"}"

Concluding Remarks

In this tutorial, we’ve learned that Aspose.Cells Cloud SDK for .NET and cURL commands offer a convenient and efficient way to convert Excel files to text format. This can be particularly useful when working with large datasets or complex formulas, as text files allow users to quickly extract the relevant information without the need for specialized software or programming skills.

Both of these approaches provide numerous benefits, including compatibility with various software applications and operating systems, improved data security, and increased efficiency due to smaller file sizes. Additionally, the Aspose.Cells Cloud SDK for .NET and cURL commands are easy to use and offer flexibility, making them a great choice for businesses and individuals alike. By leveraging the power of Aspose.Cells Cloud SDK for .NET and cURL commands, you can quickly and easily convert Excel files to text, and make your data more accessible and secure. Let’s get started today!

Please visit the following links to learn more about: