A cikin ƙaƙƙarfan kaset ɗin sarrafa bayanai, buƙatar jujjuya CSV zuwa littafin aikin Excel (XLSX /xlsx/), XLS) yana fitowa azaman muhimmin mataki. Yana ba da ƙofa zuwa ƙarin kuzari da ƙwarewar bayanai. Duk da cewa fayilolin CSV suna ba da sauƙi, amma ba shi da ingantattun ayyukan aiki da roƙon gani na Excel. A cikin wannan labarin, muna buɗe buƙatun tursasawa don canza CSV zuwa Excel. Don haka bari mu zurfafa cikin cikakkun bayanai don cike gibin da ke tsakanin danyen bayanai da kuma abubuwan da za a iya aiwatarwa ta amfani da .NET REST API, tabbatar da ingantacciyar gogewa da gogewar canjin bayanai.
- NET Cloud SDK don CSV zuwa Canjin Excel
- Canza Fayil na CSV zuwa Excel a cikin C#
- Juya CSV zuwa XLS ta amfani da Umarnin CURL
NET Cloud SDK don CSV zuwa Canjin Excel
Aspose.Cells Cloud SDK don NET yana ba da canji maras kyau daga CSV zuwa Excel (XLSX, XLS). Wannan SDK mai ƙarfi ba kawai yana sauƙaƙewa da haɓaka tsarin jujjuyawar ba har ma yana buɗe kofofin zuwa ɗimbin sauran iyakoki. Wasu daga cikin ayyukan sun haɗa da (amma ba’a iyakance ga) sarrafa takardar aikin Excel ba, ƙirƙira taswira, tsarawa na ci gaba, har ma kuna iya yin ƙididdige ƙididdiga.
Yanzu 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.
Canza Fayil na CSV zuwa Excel a cikin C#
Haɓaka tafiya mara kyau don CSV zuwa Excel (XLSX, XLS) jujjuya ta amfani da C# .NET.
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);
Ƙirƙiri wani abu na ajin CellsApi inda muke ƙaddamar da shaidar abokin ciniki azaman muhawara.
PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
Ƙirƙiri misali na WorkbookSaveAsRequest inda muke samar da sunan shigar da fayil CSV, sakamakon sunan XLS da ƴan sigogin zaɓi.
var response = cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);
Kira API don fara aikin CSV zuwa XLSX. Da zarar an yi nasarar aiwatar da lambar, ana adana sakamakon Excel a cikin ajiyar girgije.
/ For complete examples and data files, please go to
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";
// sunan resultant fayil XLS
string resultant_XLS = "output.xls";
try
{
// karanta abun ciki na shigar da fayil CSV
var file = System.IO.File.OpenRead(input_CSV);
PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
{
name = input_CSV,
newfilename = resultant_XLS,
isAutoFitRows = true,
isAutoFitColumns = true
};
// fara aikin juyawa
var response = cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);
// buga saƙon nasara idan tuba ya yi nasara
if (response != null && response.Equals("OK"))
{
Console.WriteLine("Successful conversion of CSV to Excel format !");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Juya CSV zuwa XLS ta amfani da Umarnin CURL
Juya CSV zuwa Excel ta amfani da Aspose.Cells Cloud ta umarnin cURL yana ba da hanya mai sauri da isa. Wannan tsarin yana ba da sauƙi da sauƙi na amfani, kuma yana gabatar da ƙofa zuwa bakan ƙarin damar.
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"
Da zarar muna da alamar JWT, da fatan za a aiwatar da wannan umarni don canza tsarin CSV zuwa tsarin XLS. Bayan juyawa, sakamakon aikin Excel yana adana akan ajiyar girgije.
curl -v "https://api.aspose.cloud/v3.0/cells/{inputFile}/SaveAs?newfilename={resultantFile}&isAutoFitRows=true&isAutoFitColumns=true&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"SaveFormat\": \"XLS\", \"ClearData\": true, \"CreateDirectory\": true, \"EnableHTTPCompression\": true, \"RefreshChartCache\": true, \"SortNames\": true, \"ValidateMergedAreas\": true}"
Sauya ‘inputFile’ tare da sunan shigar da fayil ɗin CSV da ke samuwa a cikin ma’ajiyar gajimare, ‘resultantFile’ tare da sunan fitarwar Excel aikin da za a ƙirƙira da ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.
Kammalawa
A ƙarshe, tafiya daga CSV zuwa Excel (XLSX, XLS) ya kasance shaida ga ɗimbin mafita da Aspose.Cells Cloud ke bayarwa. Ko ta hanyar mai amfani Aspose.Cells Cloud SDK don NET ko kuma saurin aiwatar da umarnin cURL, zaku iya samun ikon canza canjin bayanai. Ko kai mai haɓaka ƙwararrun aikace-aikace ne ko kuma mai sha’awar layin umarni da ke neman mafita cikin sauri, Aspose.Cells Cloud yana tsaye a matsayin amintaccen abokin aiki, yana sa gabaɗayan sarrafa ayyukan sarrafa bayanai ya fi inganci da fasali.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: