fitarwa Excel Charts

Fitar da ginshiƙi na Excel azaman hoto (JPG, PNG) ta amfani da C#

A cikin duniyar nazarin bayanai, hangen nesa bayanai ta amfani da jadawali da jadawali wani muhimmin bangare ne na gabatar da hadaddun bayanai cikin saukin narkewa. Excel sanannen kayan aiki ne da masu nazarin bayanai da yawa ke amfani da shi don ƙirƙirar ginshiƙi da jadawali, amma wani lokacin ya zama dole a fitar da waɗannan ginshiƙi azaman hotuna da za a yi amfani da su a cikin rahotanni, gabatarwa, ko wasu takardu. Fitar da ginshiƙi azaman hotuna shima yana da fa’idar kiyaye tsarawa da jan hankali na ainihin ginshiƙi, ko da lokacin da aka saka ta cikin takaddar da aka ƙirƙira a cikin wani shiri na daban. A cikin wannan labarin, za mu bincika yadda ake fitar da ginshiƙi Excel azaman hotuna ta amfani da yaren shirye-shiryen C#, yana ba ku fa’idodin fayyace madaidaicin bayanan gani.

API ɗin Processing na Excel

Aspose.Cells Cloud wani dandamali ne mai ƙarfi na tushen girgije wanda ke ba da fa’idodi da yawa don aiki tare da fayilolin Excel. Ko kuna buƙatar sarrafa bayanai, yin lissafi, ko samar da rahotanni, Aspose.Cells Cloud ya rufe ku. Wani fasali mai amfani musamman shine ikon fitar da sigogin Excel azaman hotuna. Don haka don fitar da ginshiƙi na Excel azaman hoto a NET, za mu yi amfani da Aspose.Cells Cloud SDK don NET. Wannan tushen tushen girgije yana ba da API mai RESTful wanda ke ba ku damar canza sigogin Excel zuwa JPG, PNG /image/png/), BMP da sauransu.

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.

Fitar da Chart na Excel azaman Hoto ta amfani da C#

Da fatan za a yi amfani da snippets code masu zuwa don fitar da ginshiƙi na Excel azaman Hoto ta amfani da C# .NET. A cikin wannan misali, za mu ajiye hoton Excel zuwa JPG.

// 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 = "source.xlsx";
// sunan takardar aiki mai ginshiƙi
string sheetName = "Sheet1";
// fihirisar ginshiƙi don fitarwa azaman hoto
int chartNumber = 0;
// Tsarin hoton sakamako azaman JPEG
string imageFormat = "JPEG";

try
{   
    // Karanta littafin aikin Excel kuma loda shi zuwa ajiyar girgije
    cellsInstance.UploadFile(input_Excel, File.OpenRead(input_Excel));
                    
    // Kira API don fitarwa ginshiƙi na Excel zuwa Hoto
    var response = cellsInstance.CellsChartsGetWorksheetChart(input_Excel, sheetName, chartNumber, imageFormat, null);

    // buga saƙon nasara idan tuba ya yi nasara
    if (response != null && response.Equals("OK"))
    {
        Console.WriteLine("Watermarks removed successfully from Excel !");
        Console.ReadKey();
    }
    
    // Ajiye sakamakon sakamakon zuwa drive na gida
    using (var fileStream = new FileStream("resultant.jpg", System.IO.FileMode.OpenOrCreate, FileAccess.Write))
    {
        response.Seek(0, SeekOrigin.Begin);
        response.CopyTo(fileStream);
    }
}
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 ajin CellsApi yayin ƙaddamar da shaidar abokin ciniki azaman muhawara.

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

Karanta fayil ɗin Excel kuma loda zuwa ajiyar girgije.

var response = cellsInstance.CellsChartsGetWorksheetChart(input_Excel, sheetName, chartNumber, imageFormat, null);

Kira API don fitarwa ginshiƙi na Excel azaman Hoto. Mun wuce ‘JPEG’ azaman sigar hoto na sakamako.

API ɗin yana goyan bayan tsarin hoto masu zuwa PNG/TIFF/JPEG/GIF/EMF/BMP.

using (var fileStream = new FileStream("resultant.jpg", System.IO.FileMode.OpenOrCreate, FileAccess.Write))
{
    response.Seek(0, SeekOrigin.Begin);
    response.CopyTo(fileStream);
}

Ajiye hoton JPG zuwa faifan gida.

Ana iya saukar da shigar da Excel da aka yi amfani da shi a cikin misalin da ke sama daga [source.xlsx] (hotuna/source.xlsx).

Ajiye Chart na Excel azaman Hoto ta amfani da Umarnin CURL

Ana iya fitar da ginshiƙi na Excel azaman hoto kuma ana iya yin amfani da umarnin Aspose.Cells Cloud da cURL. Tare da wannan zaɓin, zaku iya haɗa aikin jujjuya ginshiƙi zuwa hoto cikin sauri ba tare da buƙatar hadaddun coding ba. Ta hanyar aika buƙatu kawai zuwa Aspose.Cells Cloud API ta amfani da umarnin cURL, zaku iya canza taswirar Excel zuwa nau’ikan hoto iri-iri.

Da farko, muna buƙatar shigar da cURL akan tsarinmu sannan mu samar da damar shigaToken dangane da shaidar abokin cinikin ku:

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).

Yanzu, muna buƙatar aiwatar da umarni mai zuwa don damfara adana hoton Excel azaman hoto:

curl -v "https://api.aspose.cloud/v3.0/cells/{excelFile}/worksheets/Sheet1/charts/0?format={format}" \
-X GET \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer {accessToken}" \
-o  "Resultant.jpg"

Sauya {excelFile} tare da sunan littafin aikin Excel da ake samu a ma’ajiyar gajimare. Sauya {tsarin} da tsarin hoton da ake so, watau PNG/TIFF/JPEG/GIF/EMF/BMP. Yanzu maye gurbin {accessToken} tare da alamar shiga da aka samar a sama . Ana amfani da ma’aunin -o don zazzage abin da aka fitar akan tuƙi na gida.

Karshen Magana

A ƙarshe, fitar da ginshiƙi na Excel azaman hotuna na iya zama sifa mai fa’ida sosai lokacin da kuke buƙatar raba ko buga bayanan ku ta hanyar gani. Aspose.Cells Cloud yana ba da cikakkiyar bayani don wannan aikin, yana ba da kayan aiki da yawa da APIs waɗanda za a iya amfani da su don sauƙaƙe fitar da sigogi na Excel azaman hotuna. Haɗin dandamali tare da umarnin cURL yana ba da damar sarrafa wannan tsari, yana mai da shi mafi inganci da adana lokaci. Ko kuna aiki akan ƙaramin aiki ko babban bincike na bayanai, Aspose.Cells Cloud na iya taimaka muku cimma burin ku cikin sauri da sauƙi.

Hanyoyin haɗi masu amfani

Abubuwan da aka Shawarar

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