إدراج صورة ويب من عنوان URL داخل ورقة عمل Excel
Contents
[
Hide
]
توضح هذه المقالة كيف يمكنك إدراج صورة ويب مباشرة في Worksheet. تستخدم مقطع الكود المقدم أدناه فئات java.net و java.io بالإضافة إلى com.aspose.cells لتحقيق النتيجة المطلوبة.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(InsertWebImageFromURL.class); | |
// Download image and store it in an object of InputStream | |
URL url = new URL("https://www.google.com/images/nav_logo100633543.png"); | |
InputStream inStream = new BufferedInputStream(url.openStream()); | |
// Create a new workbook | |
Workbook book = new Workbook(); | |
// Get the first worksheet in the book | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Get the first worksheet pictures collection | |
PictureCollection pictures = sheet.getPictures(); | |
// Insert the picture from the stream to B2 cell | |
pictures.add(1, 1, inStream); | |
// Save the excel file | |
book.save(dataDir + "InsertedImage.xls"); |