raba excel

Raba fayilolin Excel (XLS, XLSX) a cikin C# .NET

Excel kayan aiki ne mai ƙarfi don sarrafawa da nazarin bayanai, amma wani lokacin, ma’amala da manyan fayilolin Excel na iya zama mai ƙarfi. Idan kun sami kanku kuna fama da fayilolin Excel waɗanda suka fi girma don sarrafa su, raba su cikin ƙananan fayiloli na iya taimakawa. Abin farin ciki, tare da NET REST API, raba fayilolin Excel na iya zama tsari mai sauƙi da inganci. A cikin wannan koyawa, za mu bi ku ta matakai na rarraba littafin aikin Excel zuwa fayiloli da yawa ta amfani da C# .NET, don haka za ku iya sarrafa bayanan ku kuma inganta aikinku.

Split Excel API

Aspose.Cells Cloud SDK don NET kayan aiki ne mai ƙarfi wanda ke ba masu haɓaka damar yin aiki tare da fayilolin Excel a cikin gajimare. Ɗaya daga cikin mahimman fasalulluka na wannan SDK shine ikon raba manyan fayilolin Excel zuwa ƙanana, waɗanda zasu iya zama da amfani mai matuƙar amfani don sarrafawa da nazarin bayanai. A cikin wannan koyawa, za mu nuna muku yadda ake amfani da wannan SDK don raba fayilolin Excel (XLS, XLSX), mataki-mataki. Ko kun kasance sababbi ga SDK ko kuma neman ƙarin koyo game da raba fayilolin Excel, jagoranmu ya rufe ku. Bari mu fara!

Don farawa, muna buƙatar ƙara bayanin sa a cikin aikace-aikacen mu ta mai sarrafa fakitin NuGet. Bincika “Aspose.Cells-Cloud” kuma danna maɓallin Ƙara Kunshin. Na biyu, idan baku da asusu akan Cloud Dashboard, da fatan za a ƙirƙiri asusun kyauta ta amfani da ingantaccen adireshin imel kuma sami keɓaɓɓen takaddun shaidarku.

Yadda ake Rarraba Excel ta amfani da C#

A cikin wannan sashe, za mu loda takaddun aiki guda biyu daga ajiyar girgije sannan mu haɗa littafin aikin Excel na biyu zuwa na farko.

// 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);

// shigar da littafin aikin Excle
string first_Excel = "myDocument.xls";

try
{    
    // loda Excel zuwa ajiyar girgije
    cellsInstance.UploadFile("myDocument.xlsx", File.OpenRead(first_Excel));
    
    // fara aikin raba Excel
    var response = cellsInstance.CellsWorkbookPostWorkbookSplit(first_Excel, "XLSX", from: 1, to: 2, null, null, null);

    // buga saƙon nasara idan haɗin kai ya yi nasara
    if (response != null && response.Equals("OK"))
    {
        Console.WriteLine("Excel Split operation completed successfully !");
        Console.ReadKey();
    }
}
catch (Exception ex)
{
    Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}

Bari mu fahimci snippet code na sama:

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

Ƙirƙiri wani abu na CellsApi yayin ƙaddamar da bayanan abokin ciniki azaman muhawara.

cellsInstance.UploadFile("myDocument.xlsx", File.OpenRead(first_Excel));

Loda shigarwar Excel zuwa ma’ajin gajimare tare da suna.

var response = cellsInstance.CellsWorkbookPostWorkbookSplit(first_Excel, "XLSX", from: 1, to: 2, null, null, null);

Kira API don fara aikin rarraba Excel. Aikin raba takardar aiki zai fara daga index 1 zuwa index 2. Sakamakon aikin za a adana shi a cikin ajiyar girgije iri ɗaya.

Excel raba

Preview na Excel tsaga.

Ana iya sauke samfurin littattafan aikin Excel da aka yi amfani da su a cikin misalin da ke sama daga myDocument.xlsx.

Raba Excel Online ta amfani da Umarnin CURL

Idan kun fi son yin aiki tare da kayan aikin layin umarni, cURL kayan aiki ne mai ƙarfi wanda ke ba ku damar canja wurin bayanai ta amfani da ka’idoji iri-iri, gami da HTTP, HTTPS, FTP, da ƙari. Ɗaya daga cikin mahimman fa’idodin amfani da umarnin cURL don rarrabuwar Excel shine yana ba ku damar sarrafa tsarin, yana sa shi sauri da inganci. Tare da umarnin cURL, zaku iya raba fayilolin Excel zuwa ƙananan ta amfani da API REST, wanda zai iya zama da amfani mai matuƙar amfani don sarrafawa da nazarin bayanai. Ko kun kasance sababbi ga cURL da REST APIs, jagorarmu za ta bi ku ta hanyar rarraba fayilolin Excel, ta yadda zaku iya sarrafa bayananku da kyau.

Bari mu fara ta hanyar samar da alamar samun damar JWT dangane da shaidar abokin ciniki:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Yanzu da muke da alamar JWT, muna buƙatar amfani da PostWorkbookSplit API don raba littafin aikin Excel. Da fatan za a aiwatar da umarni mai zuwa.

curl -v -X POST "https://api.aspose.cloud/v3.0/cells/myDocument.xlsx/split?format=XLSX&from=2&to=3&splitNameRule=ExtractSheet" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Karshen Magana

A cikin wannan koyawa, mun rufe hanyoyi guda biyu don rarraba fayilolin Excel: ta amfani da C# .NET da kuma amfani da API REST tare da umarnin cURL. Duk hanyoyin biyu suna da nasu fa’idodin, kuma zaɓin ƙarshe ya dogara da takamaiman buƙatu da abubuwan da kuke so. Tare da C# .NET, kuna da kayan aiki mai ƙarfi a wurin ku don raba fayilolin Excel akan tebur ko wayar hannu. A gefe guda, ta amfani da API REST tare da umarnin cURL yana ba ku damar sarrafa aiki da aiki da raba fayilolin Excel a cikin gajimare. Ko wace hanya kuka zaɓa, jagorarmu ta mataki-mataki ya ba ku ilimi da ƙwarewa don raba fayilolin Excel kamar ƙwararru. Fara inganta aikin ku na Excel a yau!

Hanyoyin haɗi masu amfani

Abubuwan da aka Shawarar

Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: