Excel watermark

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

Excel kayan aiki ne mai ƙarfi wanda aka fi amfani dashi don sarrafa bayanai da kuma nazarin bayanai. Kamar yadda aka san shi da farko don fasalin lambobi da sarrafa bayanai, yana kuma ba da kayan aikin tsarawa da gabatarwa da yawa masu amfani. Ɗaya daga cikin irin wannan kayan aiki shine ikon saka alamar ruwa, wanda za’a iya amfani dashi don ƙara hoton bango ko rubutu zuwa takaddun aiki Excel. Alamomin ruwa suna da amfani don ƙara abubuwan sa alama a cikin takarda, suna nuna matsayi ko sigar takardar, ko don ƙara wani yanki na kariya daga kwafi ko rarraba mara izini. A cikin wannan labarin, za mu bincika yadda ake ƙarawa da cire alamun ruwa a cikin Excel ta amfani da C#, samar da jagorar mataki-mataki ga waɗanda ke son haɓaka buƙatun gani na takaddun Excel da kuma kare mahimman abubuwan su.

Excel Watermark API

Aspose.Cells Cloud yana ba da hanya mai sauƙi da inganci don yin aiki tare da takaddun Excel a cikin girgije, yana ba ku damar daidaita aikin ku da sarrafa sarrafa yawancin ayyukanku na Excel. Sakamakon dacewa da tsarin giciye, haɗin kai maras kyau, tsaro mai ƙarfi, da ƙimar farashi, zaɓi ne mai ban mamaki don aiki tare da fayilolin Excel a cikin gajimare. Bugu da ƙari, wannan API mai ƙarfi yana ba ku damar aiwatar da ayyuka daban-daban akan takaddun Excel da tsari, gami da ƙarawa da cire alamun ruwa.

Yanzu, don saka alamar ruwa a cikin Excel ta amfani da C# .NET, muna buƙatar ƙara ma’anar Aspose.Cells Cloud SDK don NET a cikin aikinmu. Don haka, 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.

Ƙara Watermark zuwa Excel ta amfani da C#

Bari mu yi saurin dubawa kan snippet code na C# .NET don ƙara alamar ruwa zuwa littafin aikin Excel.

// 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 Excel daga faifan gida
string input_Excel = "input.xls";
// Hoton da za a yi amfani da shi azaman alamar ruwa
string imageFile = "Landscape.jpg";

// karanta hoton shigarwa don yawo misali
var imageStream = System.IO.File.OpenRead(imageFile);

try
{   
    // Karanta littafin aikin Excel kuma loda zuwa ajiyar girgije
    cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));

    // Ƙirƙiri misali memoryStream
    var memoryStream = new MemoryStream();

    // Yi amfani da hanyar .CopyTo() kuma rubuta rafin fayil na yanzu zuwa rafin ƙwaƙwalwa
    imageStream.CopyTo(memoryStream);

    // Maida Rafi Zuwa Tsara
    byte[] imageBytes = memoryStream.ToArray();
                    
    // Ƙara alamar ruwa zuwa littafin aikin Excel
    var response = cellsInstance.CellsWorkbookPutWorkbookBackground(input_Excel, imageBytes, null);

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

Ana ba da cikakkun bayanai na snippet na sama:

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

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

var imageStream = System.IO.File.OpenRead(imageFile);

Karanta hoton shigarwa zuwa misali FileStream.

cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));

Loda shigarwar Excel zuwa ma’ajin gajimare.

var memoryStream = new MemoryStream();
imageStream.CopyTo(memoryStream);
byte[] imageBytes = memoryStream.ToArray();

Ana canza shigarwar FileStream zuwa ByteArray.

var response = cellsInstance.CellsWorkbookPutWorkbookBackground(input_Excel, imageBytes, null);

A ƙarshe, muna kiran API don ƙara alamar ruwa zuwa Excel kuma adana sakamakon aikin Aiki zuwa ajiyar girgije.

Ana iya sauke shigar da fayilolin Excel da Hotunan da aka yi amfani da su a cikin misalin da ke sama daga input.xls da [Landscape.jpg](https://media.photographycourse.net/wp-content/uploads/ 2014/11/08164934/Landscape-Photography-steps.jpg) bi da bi.

Cire alamar ruwa ta Excel ta amfani da C#

Tare da Aspose.Cells Cloud, cire alamar ruwa daga takardun Excel yana da sauri da sauƙi, yana ba ku damar daidaita aikin ku da sarrafa yawancin ayyukanku na Excel. Wannan aikin yana da amfani lokacin da kuke buƙatar sabuntawa ko maye gurbin alamar ruwa da ke akwai, ko kuma idan kuna son cire shi gaba ɗaya. Tare da Aspose.Cells Cloud API, zaka iya cire alamar ruwa cikin sauƙi daga duk takaddun aikin Excel. API ɗin zai cire alamar ruwa daga ƙayyadadden takaddar aiki, yana barin sauran takaddun ba canzawa.

// 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 Excel tare da alamun ruwa akan tuƙi na gida
string input_Excel = "input.xls";

try
{   
    // Karanta littafin aikin Excel kuma loda zuwa ajiyar girgije
    cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));
                    
    // Kira API don cire alamar ruwa daga duk takaddun aikin Excel
    var response = cellsInstance.CellsWorkbookDeleteWorkbookBackground(input_Excel, null);

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

A cikin snippet na sama, bin layin lamba yana da alhakin cire hotunan alamar ruwa daga littafin aikin Excel.

var response = cellsInstance.CellsWorkbookDeleteWorkbookBackground(input_Excel, null);

Saita Hoton Baya na Excel ta amfani da Umarnin CURL

Aspose.Cells Cloud yana ba da API REST mai sauƙi kuma mai sauƙi don amfani, yana ba ku damar haɗa ayyukan takaddun ruwa na Excel a cikin ayyukanku na yau da kullun. Bugu da ƙari, tare da taimakon umarnin cURL, za mu iya sarrafa wannan aiki ta atomatik kuma mu sauƙaƙe ayyukanmu masu alaƙa da Excel. Yanzu, don ƙara alamar ruwa, muna buƙatar aika buƙatun CURL POST zuwa Aspose.Cells Cloud API tare da saitunan alamar ruwa da fayil ɗin takaddar Excel azaman sigogi.

Koyaya, da farko muna buƙatar shigar da cURL akan tsarinmu sannan mu samar da damar shigaToken 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"

Na biyu, yi amfani da umarni mai zuwa don loda shigar da Excel zuwa ma’ajiyar gajimare:

curl -v "https://api.aspose.cloud/v3.0/cells/storage/file/{filePath}" \
-X PUT \
-F file=@{localFilePath} \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer {accessToken}"

Sauya {filePath} tare da hanyar da kake son adana fayil ɗin a cikin ma’ajiyar gajimare, `{localFilePath}’ tare da hanyar Excel akan tsarin gida, da ‘‘accessToken}’ tare da alamar samun damar Aspose Cloud. (wanda aka samar a sama).

A ƙarshe, aiwatar da umarni mai zuwa don saka alamar ruwa a cikin littafin aikin Excel akan layi:

curl -v "https://api.aspose.cloud/v3.0/cells/{excelFile}/background" \
-X PUT \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer {accessToken}" \
-H  "Content-Type: multipart/form-data" \
-d  "File":{"watermarkImage"}

Sauya {excelFile} da sunan shigar da fayil na Excel a cikin ma’ajiyar gajimare Sauya {accessToken} tare da alamar shiga da aka samar a sama Maye gurbin {watermarkImage} tare da hoton raster da ake samu akan faifan gida

  • Bayan aiki mai nasara, za a adana alamar ruwa ta Excel a cikin ma’ajin girgije iri ɗaya.

Karshen Magana

Gabaɗaya, ƙara da cire alamun ruwa a cikin takaddun Excel na iya taimakawa don kare bayanan ku da kiyaye amincin takaddar. Aspose.Cells Cloud yana ba da mafita mai ƙarfi don cim ma waɗannan ayyuka a cikin sauƙi da daidaitacce. Ta amfani da Aspose.Cells Cloud API da umarnin cURL, zaku iya sarrafa waɗannan hanyoyin cikin sauƙi kuma ku haɗa su cikin ayyukanku na yanzu. Tare da ƙarin fasalulluka kamar fassarar daftarin aiki, tsarawa, da magudi, Aspose.Cells Cloud kayan aiki ne mai mahimmanci don sarrafa takaddun Excel ɗinku a cikin gajimare.

Hanyoyin haɗi masu amfani

Abubuwan da aka Shawarar

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