Created
September 14, 2024 15:15
-
-
Save aspose-cloud-kb/eae4cc0cfe85cc5ba36509a86cb0cd84 to your computer and use it in GitHub Desktop.
Convert XLSX to CSV with NET REST API. https://kb.aspose.cloud/cells/net/convert-xlsx-to-csv-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Cells.Cloud.SDK.Api; | |
using Aspose.Cells.Cloud.SDK.Request; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace Kb_Aspose.KB | |
{ | |
public class XlsxToCsvConverter | |
{ | |
public void XlsxToCsv() | |
{ | |
try | |
{ | |
string clientID = "ID"; | |
string clientSecret = "Secret"; | |
string apiBaseUrl = "https://api.aspose.cloud"; | |
// Source and output file names | |
string localPath = "C:/ExcelFiles/"; | |
string inputFileName = "Source.xlsx"; | |
string outputFileName = "XlsxtoCsv.csv"; | |
CellsApi xlsxtoCsvApi = new CellsApi(clientID, clientSecret, apiBaseUrl); | |
var xlsxToCsvRequest = new PostConvertWorkbookToCSVRequest() | |
{ | |
checkExcelRestriction = true, | |
File = new Dictionary<string, Stream>() | |
{ | |
{ | |
inputFileName, File.OpenRead(localPath + inputFileName) | |
} | |
}, | |
}; | |
var response = xlsxtoCsvApi.PostConvertWorkbookToCSV(xlsxToCsvRequest); | |
File.WriteAllBytes(localPath + outputFileName, Convert.FromBase64String(response.FileContent)); | |
Console.WriteLine("XLSX to CSV conversion completed"); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment