Bir URL den Web Resmini Excel Çalışma Sayfasına Yükleme

Bir URL’den Bir Resmi Excel Çalışma Sayfasına Yükleme

Aspose.Cells for Python via .NET API, URL’den resimleri Excel Çalışma Sayfalarına yüklemek için basit ve kolay bir yol sağlar. Bu makale, resmi verisini bir akışa indirerek ve ardından Aspose.Cells for Python via .NET API’sini kullanarak çalışma sayfasına eklemeyi açıklar. Bu yöntemi kullanarak, resimler excel dosyasının bir parçası olur ve çalışma sayfası her açıldığında indirilmez.

Örnek Kod

import requests
from PIL import Image
import io
from aspose.cells import Workbook, CellsHelper
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
# Define memory stream object
obj_image = io.BytesIO()
# Define a string which will hold the web image url
s_url = "https://docs.aspose.com/cells/images/Aspose-image-for-open-graph.jpg"
try:
# Instantiate the web client object
response = requests.get(s_url)
# Now, extract data into memory stream downloading the image data into the array of bytes
obj_image.write(response.content)
# Create a new workbook
wb = Workbook()
# Get the first worksheet in the book
sheet = wb.worksheets[0]
# Get the first worksheet pictures collection
picts = sheet.pictures
# Insert the picture from the stream to B2 cell
picts.add(1, 1, obj_image)
# Save the excel file
wb.save("webimagebook.out.xlsx")
except Exception as ex:
# Write the error message on the console
print(ex)