Haɗa fayiloli Excel na iya zama dabara mai amfani don daidaita sarrafa bayanai. Ko kuna buƙatar ƙarfafa rahotannin tallace-tallace, bayanan kuɗi, ko bayanan abokin ciniki, haɗa fayilolin Excel na iya ceton ku lokaci da ƙoƙari. A cikin wannan labarin, za mu bincika yadda ake haɗa fayilolin Excel ta amfani da C# .NET da REST API. Za mu rufe yanayi daban-daban inda haɗin kai zai iya zama da amfani, kamar lokacin da kuke da fayiloli da yawa tare da tsarin bayanai iri ɗaya, ko lokacin da kuke buƙatar haɗa bayanai daga tsari daban-daban. Za ku koyi yadda ake rubuta lamba mai sauƙi kuma mai inganci don sarrafa tsarin haɗawa da guje wa kurakuran hannu. Don haka, bari mu nutse cikin duniyar haɗin gwiwar Excel kuma mu sauƙaƙe tafiyarku a yau.
Concatenate Excel REST API
Idan kana neman ingantacciyar hanya madaidaiciya don haɗa fayilolin Excel ta amfani da C# .NET, to Aspose.Cells Cloud SDK babban zaɓi ne. Yana ba da sauƙi mai sauƙi don haɗa XLS, XLSX, da sauran tsarin fayil ta amfani da REST APIs. Ta amfani da wannan tushen tushen girgije, zaku iya kawar da buƙatar shigar da hadaddun software da kayan aikin hardware. Aspose.Cells Cloud SDK for NET kuma yana ba da fasali kamar layuka da ginshiƙai masu dacewa da kai-da-kai, rarrabuwar bayanai, da amfani da tsarawa zuwa sel da aka haɗa. Ta amfani da wannan API, zaku iya rage lokacin haɓakawa da ƙoƙari sosai da haɓaka yawan aiki.
Yanzu, don amfani da SDK, za mu ƙara bayanin sa a cikin aikace-aikacen mu ta mai sarrafa fakitin NuGet. Kawai bincika “Aspose.Cells-Cloud” kuma danna maɓallin Ƙara Kunshin. Na biyu, idan ba ku da asusu akan Cloud Dashboard, da fatan za a ƙirƙiri asusun kyauta ta amfani da ingantaccen adireshin imel kuma sami keɓaɓɓen shaidar abokin ciniki.
Haɗa 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);
// Littafin aikin farko na Excle akan tuƙi
string first_Excel = "input.xls";
// sunan littafin aikin Excel na biyu
string second_Excel = "myDocument.xlsx";
// ƙirƙiri abu na ƙamus don riƙe shigar da littattafan aikin Excel
Dictionary<String, Stream> mapFiles = new Dictionary<string, Stream>();
mapFiles.Add(first_Excel, File.OpenRead(first_Excel));
mapFiles.Add(second_Excel, File.OpenRead(second_Excel));
// shigar da fayilolin Excel zuwa ma'ajiyar Cloud
try
{
foreach (KeyValuePair<String, Stream> dictionary in mapFiles)
{
// loda kowane littafin aiki zuwa ajiyar girgije
cellsInstance.UploadFile(dictionary.Key, dictionary.Value);
}
}
catch(Exception ex)
{
// duk wani Keɓanta duirng fayil loda zuwa Cloud ajiya
Console.Write(ex.StackTrace);
}
try
{
// fara aikin haɗin gwiwar Excel
var response = cellsInstance.CellsWorkbookPostWorkbooksMerge(first_Excel, second_Excel, folder: null, storageName: null, mergedStorageName: null);
// buga saƙon nasara idan haɗin kai ya yi nasara
if (response != null && response.Equals("OK"))
{
Console.WriteLine("Concatenate Excel operation completed successfully !");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Bari mu haɓaka fahimtarmu game da snippet na sama:
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);
Ƙirƙiri wani abu na CellsApi yayin ƙaddamar da bayanan abokin ciniki azaman muhawara.
Dictionary<String, Stream> mapFiles = new Dictionary<string, Stream>();
Ƙirƙiri abu na ƙamus wanda zai riƙe sunaye da abun ciki na shigar da littattafan aikin Excel
mapFiles.Add(first_Excel, File.OpenRead(first_Excel));
Ƙara shigar da fayilolin Excel zuwa abu na ƙamus. Muna ƙara fayiloli a cikin nau’i-nau’i masu ƙima.
foreach (KeyValuePair<String, Stream> dictionary in mapFiles)
{
// upload each workbook to cloud storage
cellsInstance.UploadFile(dictionary.Key, dictionary.Value);
}
Yi maimaita ta misalin ƙamus kuma loda kowane littafin aikin Excel zuwa ajiyar girgije.
// initialize the conversion operation
var response = cellsInstance.CellsWorkbookPostWorkbooksMerge(first_Excel, second_Excel, folder: null, storageName: null, mergedStorageName: null);
Kira hanyar don fara aikin haɗin gwiwar Excel. Duk takardun aiki daga littafin aikin Excel na biyu an haɗa su zuwa littafin aikin Excel na farko.
Ana iya sauke samfurin littattafan aikin Excel da aka yi amfani da su a cikin misalin da ke sama daga myDocument.xlsx da TestCase.xlsx bi da bi.
Haɗa Excel ta amfani da Umarnin CURL
Haɗa fayilolin Excel ta amfani da REST API kyakkyawar hanya ce. API ɗin REST yana ba da hanya mai sauƙi da inganci don haɗa fayilolin Excel kuma ana iya haɗa su cikin sauƙi tare da sauran kayan aikin software. Ɗaya daga cikin manyan ƙarfin amfani da REST API shine ikon yin aiki tare da nau’ikan fayil daban-daban, gami da XLS, XLSX, CSV, da ƙari. Bugu da ƙari, APIs na REST suna da ƙima sosai kuma suna iya ɗaukar manyan saitin bayanai, yana mai da su kyakkyawan zaɓi don sarrafa bayanan matakin kasuwanci. Lokacin haɗa littattafan aikin Excel ta amfani da APIs REST, zaku iya adana lokacin haɓakawa da ƙoƙarinku, haɓaka daidaiton bayanai, da sauƙaƙe tafiyarku aiki.
Yanzu, da farko muna buƙatar 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"
Da zarar muna da alamar JWT, muna buƙatar amfani da PostWorkbooksMerge API don haɗa littattafan aikin Excel. Haɗin Excel ɗin zai kasance a cikin ma’ajiyar gajimare.
curl -v -X POST "https://api.aspose.cloud/v3.0/cells/TestCase.xlsx/merge?mergeWith=myDocument(1).xlsx" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Karshen Magana
A ƙarshe, haɗa fayilolin Excel ta amfani da C# .NET da REST APIs hanya ce mai inganci don daidaita tsarin sarrafa bayanan ku da haɓaka yawan aiki. Ko kuna buƙatar ƙarfafa bayanai daga tushe da yawa (XLS, XLSX da sauransu) ko sarrafa ayyuka masu maimaitawa, haɗa fayilolin Excel na iya adana lokaci da ƙoƙari. Ta hanyar amfani da ikon tushen girgije na REST APIs, zaku iya aiwatar da ayyukan sarrafa bayanai ba tare da buƙatar shigar da software mai rikitarwa ko kayan aikin kayan masarufi ba. Mun kuma koyi cewa ana iya amfani da umarnin CURL don gwadawa da haɗa REST APIs tare da sauran kayan aikin software. Don haka, ko kai mafari ne ko ƙwararren mai haɓakawa, haɗa fayilolin Excel ta amfani da REST API da umarnin CURL wata hanya ce da yakamata a yi la’akari da ita. A ƙarshe, ta bin matakai masu sauƙi da aka zayyana a cikin wannan labarin, za ku iya fara haɗa fayilolin Excel cikin sauƙi da daidaita aikin ku.
Idan kun ci karo da kowace matsala yayin amfani da API, da fatan za a tuntuɓe mu ta [ dandalin tallafin abokin ciniki 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: