For data manipulation and interoperability, the seamless conversion of CSV (Comma-Separated Values) files to plain text (TXT) format stands as a crucial step in data processing pipelines. The need to translate structured CSV data into a more versatile and universally readable TXT format is a common necessity across various industries and applications. In this comprehensive guide, we are going to delve into the significance of this conversion. So, let’s explore the details on how we can harness the power of .NET REST API and streamline this transformation process.
- .NET Cloud SDK for CSV to TXT Conversion
- Convert CSV to TXT in C# .NET
- CSV File to Text File using cURL Commands
.NET Cloud SDK for CSV to TXT Conversion
Aspose.Cells Cloud SDK for .NET provides a robust solution for seamless CSV to Text file transformation. This Cloud SDK simplifies this conversion process by offering a comprehensive set of functionalities tailored for efficient file conversions. By leveraging the power of this SDK, you can effortlessly translate CSV files into TXT format, ensuring compatibility, readability, and versatility of the data across different platforms and systems.
In order to use the SDK, we need 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 CSV to TXT in C# .NET
We have learned that the SDK not just facilitates the transformation itself but also offers additional functionalities for customization, allowing you to tailor the output TXT file according to specific formatting requirements. Now, let’s delve into the details on how we can accomplish the requirement of CSV to TXT format in C# .NET.
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);
Firstly, create an object of CellsApi class where we pass client credentials as arguments.
SaveOptions saveOptions = new SaveOptions()
Secondly, create an instance of SaveOptions class where we define the output format as TXT.
PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
Thirdly, create an instance of PostWorkbookSaveAsRequest
where we specify the name of input CSV file, name of resultant Text file.
cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);
Finally, call the API to convert CSV to TXT online. After successful conversion, the resultant Text file is stored in cloud storage.
The sample CSV file and resultant TSV can be downloaded from:
CSV File to Text File using cURL Commands
Converting CSV to a text file using Aspose.Cells Cloud through cURL commands involves utilizing the RESTful API endpoints provided by Aspose.Cells Cloud. These endpoints enable seamless file format transformations, including the conversion from CSV to TXT. Furthermore, the cURL commands act as a bridge between your local environment and the Aspose.Cells Cloud API, allowing you to interact with the API endpoints directly from the command line.
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 transform CSV to TXT file format. After the conversion, the resultant TXT file is stored in cloud storage.
curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename={output}&isAutoFitRows=true&isAutoFitColumns=true&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"SaveFormat\": \"TXT\", \"ClearData\": true, \"CreateDirectory\": true, \"EnableHTTPCompression\": true, \"RefreshChartCache\": true, \"SortNames\": true, \"ValidateMergedAreas\": true}"
Replace sourceFile
with the name of input CSV file available in Cloud storage, output
with the name of resultant TSV file to be generated in cloud storage and accessToken
with JWT access token generated above.
Conclusion
In this comprehensive article, we explored the efficient conversion of CSV (Comma-Separated Values) files to TXT (plain text) format using Aspose.Cells Cloud. This exploration encompassed and leveraged the robust Aspose.Cells Cloud SDK for .NET, showcasing its capabilities to seamlessly transform structured data from CSV to TXT files. The process involves harnessing RESTful API endpoints, enabling you to craft cURL commands that trigger format conversions directly from the command line interface.
Useful Links
Related Articles
We highly recommend visiting the following blogs: