Excel watermark

Yadda ake saka alamar ruwa a cikin Excel (XLS, XLSX) ta amfani da C#

Excel kayan aiki ne mai ban mamaki don nazarin bayanai da samar da rahotanni, amma yayin da littattafan aikin ku ke girma da girma da rikitarwa, yana iya zama da wahala a sarrafa da raba su yadda ya kamata. Manya-manyan fayiloli Excel na iya ɗaukar sararin ajiya mai mahimmanci, rage jinkirin kwamfutarka, da sanya shi wahalar yin aiki tare da wasu. Wannan shine inda matsawa littattafan aikin Excel ɗinku ke shigowa. Ta hanyar rage girman fayil ɗin, zaku iya sauƙaƙe don adanawa, raba, da aiki tare da fayilolin Excel ɗinku, ba tare da sadaukar da kowane bayanai ko ayyukan da kuke buƙata ba. A cikin wannan labarin, za mu koyi matakai kan yadda ake damfara littattafan aikin Excel da rage girman fayil ta amfani da C# .NET & Rest API.

API don matsawa Fayil na Excel

Ɗaya daga cikin zaɓuɓɓuka don damfara littattafan aikin Excel shine amfani da API na Aspose.Cells Cloud. Aspose.Cells Cloud yana ba da hanya mai sauƙi da ƙarfi don aiki tare da fayilolin Excel a cikin girgije, gami da ikon damfara su don rage girman su. Tare da Aspose.Cells Cloud, zaku iya damfara littattafan aikin ku na Excel ta amfani da algorithms iri-iri na matsawa ko saka matakin matsawa. Wadannan damar suna ba ku iko mafi girma akan tsarin matsawa. Kuma saboda Aspose.Cells Cloud shine mafita na tushen girgije, zaku iya damfara fayilolin Excel ɗinku daga ko’ina, ba tare da shigar da kowace software akan injin ku ba.

Bugu da ƙari, yin amfani da SDK ita ce hanya mafi kyau don haɓaka haɓakawa. SDK yana kula da ƙananan bayanai kuma yana ba ku damar mai da hankali kan ayyukan aikin ku. Don haka, gwargwadon iyakar wannan labarin, za mu ƙara ambaton Aspose.Cells Cloud SDK don NET a cikin aikinmu. Don haka, da fatan za a bincika Aspose.Cells-Cloud a cikin manajan fakitin NuGet kuma danna maɓallin “Ƙara Kunshin”. Bugu da ƙari, muna kuma buƙatar ƙirƙirar asusu akan Dashboard ta amfani da ingantaccen adireshin imel.

Matsa Excel ta amfani da C#

An ba da ƙasa akwai snippet code don matsa girman fayil ɗin Excel ta amfani da C# .NET.

// 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
LightCellsApi lightCellsApi = new LightCellsApi(clientID, clientSecret);

// Shigar da littafin aikin Excel akan faifan gida
string input_Excel = "input.xls";

// ƙirƙiri ID ɗin ID inda za mu ƙara fayil ɗin Excel azaman abubuwa
IDictionary<string, Stream> mapFiles = new Dictionary<string, Stream>();
mapFiles.Add(input_Excel, File.OpenRead(@input_Excel));

// kira API don matsawa fayil ɗin Excel
Aspose.Cells.Cloud.SDK.Model.FilesResult filesResult = lightCellsApi.PostCompress(mapFiles, 1,false);

// buga saƙon nasara idan matsawa ya yi nasara
if (filesResult != null && filesResult.Equals("OK"))
{
    Console.WriteLine("Compress Excel file operation completed successfully!");
    Console.ReadKey();
}

Ana ba da cikakkun bayanai na snippet na sama:

LightCellsApi lightCellsApi = new LightCellsApi(clientID, clientSecret);

Ƙirƙiri wani abu na ajin LightCellsApi yayin ƙaddamar da shaidar abokin ciniki azaman muhawara.

vIDictionary<string, Stream> mapFiles = new Dictionary<string, Stream>();
mapFiles.Add("source.xlsx", File.OpenRead(@"source.xlsx"));

Ƙirƙiri abu na ID inda muke karantawa da ƙara shigar da fayilolin Excel daga ma’ajin gida.

Aspose.Cells.Cloud.SDK.Model.FilesResult filesResult = lightCellsApi.PostCompress(mapFiles, 1,false);

Kira API don matsawa fayil ɗin Excel, kuma mun ayyana matakin matsawa a matsayin ‘1’.

Za a iya sauke littafin shigar da Excel da aka yi amfani da shi a cikin misalin da ke sama daga input.xls.

Rage Girman Fayil na Excel ta amfani da Umarnin CURL

Wata hanyar da za a damfara littattafan aikin Excel ita ce amfani da umarnin cURL tare da Aspose.Cells Cloud API. Wannan tsarin yana ba da fa’idodi da yawa, kamar ikon sarrafa tsarin matsawa ta amfani da rubutun rubutu da fayilolin tsari, da ikon haɗa ayyukan matsawa kai tsaye cikin aikace-aikacen software na ku. Tare da umarnin Aspose.Cells Cloud da cURL, zaku iya damfara littattafan aikin Excel ɗinku da sauri da sauƙi, ta amfani da matakan matsawa da yawa don cimma ma’auni mafi kyau na girman fayil da inganci.

Yanzu, da zarar mun shigar da cURL akan tsarin ku, samar da damar shiga Token dangane da bayanan 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, aiwatar da umarni mai zuwa don damfara fayil ɗin Excel zuwa ƙaramin girman:

curl -v "https://api.aspose.cloud/v3.0/cells/compress?CompressLevel=1&checkExcelRestriction=true" \
-X POST \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}" \
-H  "Content-Type: multipart/form-data" \
-d  "File":{"excelFile"}

Sauya {excelFile} da sunan shigar da fayil na Excel a cikin ma’ajin gajimare Sauya {accessToken} tare da alamar shiga da aka samar a sama

  • Hakanan za mu iya zazzage fayil ɗin da aka matsa zuwa faifan gida ta amfani da –o gardama.

Karshen Magana

A ƙarshe, matsawa littattafan aikin Excel wani muhimmin aiki ne wanda zai iya taimakawa wajen adana sararin faifai da rage zirga-zirgar hanyar sadarwa yayin aiki tare da adadi mai yawa na bayanai. Tare da umarnin Aspose.Cells Cloud da cURL, kuna da kayan aiki masu ƙarfi da sassauƙa a wurin ku don cika wannan aikin cikin sauri da inganci. Ko kun fi son amfani da Aspose.Cells Cloud SDK don NET ko don yin aiki kai tsaye tare da umarnin cURL, zaku iya damfara littattafan aikin Excel ɗinku zuwa ƙaramin girman ba tare da lalata inganci ba. Don haka me zai hana a gwada shi a yau kuma ku ga nawa sararin faifai da bandwidth za ku iya ajiyewa?

Hanyoyin haɗi masu amfani

Abubuwan da aka Shawarar

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