txt to csv

Convert TXT to CSV with .NET Cloud SDK.

In the dynamic landscape of data processing, the need to convert plain text (TXT) files to CSV format stands as a crucial imperative. Enter the realm of TXT to CSV conversion using .NET REST API, a transformative solution designed to address the growing demand for efficient data interchangeability. So this article unfolds the pressing need for this conversion, delving into the intricacies of data management and highlighting the distinctive benefits that this process brings.

REST API for TXT to CSV Conversion

The task of converting plain text (TXT) files to CSV format is made efficient and seamless with the Aspose.Cells Cloud SDK for .NET. This robust API simplifies the conversion process, allowing developers to leverage the powerful features of Aspose.Cells for streamlined data manipulation. Furthermore, this approach not only simplifies the conversion process but also unlocks the broader capabilities of Aspose.Cells Cloud SDK, making it an invaluable asset for developers seeking advanced data manipulation and interchangeability.

The first is to search Aspose.Cells-Cloud in NuGet packages manager and click the Add Package button. Secondly, obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.

Convert Text File to CSV in C# .NET

The following section explains the steps on how we can programmatically convert Text file to CSV format using C# .NET.

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

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

 cellsInstance.UploadFile("input.txt", inputFile);

Read input Text file and upload it to the cloud storage.

var response = cellsInstance.CellsWorkbookGetWorkbook("input.txt", null, format: "CSV", isAutoFit: true, null, null, null, "output.csv", null);

Initiate TXT to CSV conversion routine. The resultant CSV is then uploaded to the cloud storage.

  • In case you want to directly convert the input TXT from local drive to CSV format, please try using following code snippet.
txt to csv preview

A preview of TXT to CSV conversion using .NET REST API.

The input Text file and resultant CSV generated in the above example can be downloaded from:

TXT to CSV Conversion using cURL Commands

Aspose.Cells Cloud, a powerful API for Excel manipulation, seamlessly integrates with cURL to provide you with a versatile solution for TXT to CSV conversion. By employing cURL commands to interact with the Aspose.Cells Cloud API, you can initiate the conversion process in a straightforward and scalable manner. Furthermore, it brings the benefits of a cloud-based architecture, ensuring scalability and reducing the reliance on local resources.

The first step in this approach is to generate a JWT access token using the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=921363a8-b195-426c-85f7-7d458b112383&client_secret=2bf81fca2f3ca1790e405c904b94d233" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now, please execute the following command to convert the Text file to CSV format online. The input TXT file shall be in cloud storage and after conversion, the resultant CSV is then stored in the cloud storage.

curl -o "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=CSV&isAutoFit=true&onlySaveTable=true&outPath={resultantFile}&checkExcelRestriction=true" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}"

Replace sourceFile with the name of input TXT file, resultantFile with the name of resultant CSV and accessToken with a JWT access token generated above.

  • In order to save the resultant Excel to be stored on local drive, please use the following cURL command, where we have skipped the resultant file name and have used -o argument to specify the resultant path.
curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=CSV&isAutoFit=true&onlySaveTable=true&checkExcelRestriction=true" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-o "output.csv"

Conclusion

In conclusion, the decision to convert plain text (TXT) files to CSV format either using .NET REST API or the Aspose.Cells Cloud along with cURL commands, offer commendable solutions. This Cloud API not only simplifies the TXT to CSV conversion process, but elevates the entire data manipulation experience. Furthermore, the rich set of features, cloud scalability, and seamless integration with cURL commands, Aspose.Cells Cloud emerges as a comprehensive solution that transcends conventional boundaries.

We highly recommend visiting the following blogs: