Don sarrafa bayanai da aiki tare, juzu’in juzu’i na CSV (Wakafi-Separated Values) fayiloli zuwa rubutu a sarari ([TXT](https://docs. fileformat.com/word-processing/txt/))) Tsarin yana tsaye a matsayin muhimmin mataki na sarrafa bututun bayanai. Bukatar fassara bayanan CSV da aka tsara zuwa mafi dacewa da tsarin TXT wanda za’a iya karantawa a duk duniya wata bukata ce ta gama gari a cikin masana’antu da aikace-aikace daban-daban. A cikin wannan cikakken jagorar, za mu zurfafa cikin mahimmancin wannan tuba. Don haka, bari mu bincika cikakkun bayanai kan yadda za mu iya amfani da ikon .NET REST API kuma mu daidaita wannan tsarin canji.
- NET Cloud SDK don CSV zuwa Canjawar TXT
- Maida CSV zuwa TXT a cikin C# .NET
- Fayil CSV zuwa Fayil Rubutu ta amfani da Umarnin CURL
NET Cloud SDK don CSV zuwa Canjawar TXT
Aspose.Cells Cloud SDK don .NET yana ba da ingantaccen bayani don CSV maras kyau zuwa sauya fayil ɗin rubutu. Wannan Cloud SDK yana sauƙaƙa wannan tsarin jujjuyawar ta hanyar ba da cikakkiyar saiti na ayyuka waɗanda aka keɓance don ingantaccen jujjuyawar fayil. Ta hanyar amfani da ƙarfin wannan SDK, zaku iya fassara fayilolin CSV cikin wahala zuwa tsarin TXT, tabbatar da dacewa, iya karantawa, da juzu’in bayanai a kan dandamali da tsarin daban-daban.
Domin amfani da SDK, muna buƙatar bincika ‘Aspose.Cells-Cloud’ a cikin manajan fakitin NuGet kuma danna maɓallin ‘Ƙara Kunshin’. Na biyu, sami takaddun shaidar abokin ciniki daga dashboard ɗin girgije. Idan ba ku da asusun da ke akwai, kawai ƙirƙirar asusun kyauta ta bin umarnin da aka kayyade a cikin labarin saurin farawa.
Maida CSV zuwa TXT a cikin C# .NET
Mun koyi cewa SDK ba wai yana sauƙaƙe sauƙaƙa da kansa ba amma yana ba da ƙarin ayyuka don keɓancewa, yana ba ku damar daidaita fayil ɗin TXT mai fitarwa bisa ga takamaiman buƙatun tsarawa. Yanzu, bari mu shiga cikin cikakkun bayanai kan yadda za mu iya cika buƙatun CSV zuwa tsarin TXT a cikin C# .NET.
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);
Da farko, ƙirƙiri wani abu na ajin CellsApi inda muke ƙaddamar da shaidar abokin ciniki azaman muhawara.
SaveOptions saveOptions = new SaveOptions()
Na biyu, ƙirƙirar misali na ajin SaveOptions inda muke ayyana tsarin fitarwa azaman TXT.
PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
Na uku, ƙirƙiri misali na ‘PostWorkbookSaveAsRequest’ inda muka ƙididdige sunan shigar da fayil ɗin CSV, sunan fayil ɗin rubutu na sakamakon.
cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);
A ƙarshe, kira API don canza CSV zuwa TXT akan layi. Bayan nasarar yin nasara, ana adana babban fayil ɗin Rubutu a cikin ma’ajin gajimare.
// Don cikakkun misalai da fayilolin bayanai, da fatan za a je zuwa
https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/
// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
// ƙirƙiri misalin CellsApi yayin wuce ClientID da ClientSecret
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);
// sunan shigar da fayil CSV
string input_CSV = "source.csv";
// Fayil Rubutun Sakamako
string resultant_file = "resultant.txt";
try
{
// karanta abun ciki na shigar da fayil CSV
var file = System.IO.File.OpenRead(input_CSV);
// SaveOption abu yana bayyana tsarin fitarwa azaman TXT
SaveOptions saveOptions = new SaveOptions()
{
SaveFormat = "TXT",
ClearData = true
};
// Buƙatar adana littafin aiki
PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
{
name = input_CSV,
newfilename = resultant_file
};
// fara aikin juyawa
var response = cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);
// lokacin da tuba ta yi nasara, buga saƙon nasara
if (response != null && response.Equals("OK"))
{
Console.WriteLine("The CSV to Text file conversion completed successfully !");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Za a iya sauke samfurin fayil na CSV da sakamakon TSV daga:
Fayil ɗin CSV zuwa Fayil ɗin Rubutu ta amfani da Umarnin CURL
Mayar da CSV zuwa fayil ɗin rubutu ta amfani da Aspose.Cells Cloud ta umarnin cURL ya ƙunshi amfani da ƙarshen API na RESTful wanda Aspose.Cells Cloud ya bayar. Waɗannan wuraren ƙarshen suna ba da damar sauye-sauyen tsarin fayil mara sumul, gami da juyawa daga CSV zuwa TXT. Bugu da ƙari, umarnin cURL suna aiki azaman gada tsakanin yanayin gida da Aspose.Cells Cloud API, yana ba ku damar yin hulɗa tare da ƙarshen API kai tsaye daga layin umarni.
Mataki na farko a wannan hanyar shine samar da alamar samun damar JWT ta amfani da umarni mai zuwa:
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"
Yanzu, da fatan za a aiwatar da umarni mai zuwa don canza CSV zuwa tsarin fayil na TXT. Bayan jujjuyawa, ana adana sakamakon TXT a cikin ma’ajin gajimare.
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}"
Sauya ‘sourceFile’ tare da sunan shigar da fayil ɗin CSV da ke samuwa a cikin ma’ajiyar girgije, ‘‘fitarwa’ tare da sunan sakamakon fayil ɗin TSV da za a ƙirƙira a cikin ma’ajin gajimare da ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.
Kammalawa
A cikin wannan cikakkiyar labarin, mun bincika ingantaccen jujjuya fayilolin CSV (Wakafi-Raba Ƙimar) zuwa tsarin TXT (rubutu a sarari) ta amfani da Aspose.Cells Cloud. Wannan binciken ya ƙunshi kuma ya ba da ƙarfin Aspose.Cells Cloud SDK don NET, yana nuna ƙarfinsa don canza bayanan da aka tsara daga CSV zuwa fayilolin TXT ba tare da matsala ba. Tsarin ya ƙunshi haɗar wuraren ƙarshen API na RESTful, yana ba ku damar ƙera umarnin cURL waɗanda ke haifar da jujjuya tsarin kai tsaye daga ƙirar layin umarni.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: