قم بإدراج صورة بناءً على مرجع Cell
Contents
[
Hide
]
في بعض الأحيان يكون لديك صورة فارغة وتحتاج إلى إظهار البيانات أو المحتويات في الصورة عن طريق تعيين مرجع خلية في شريط الصيغة. يدعم Aspose.Cells هذه الميزة (Microsoft Excel 2010).
إدراج صورة بناءً على مرجع Cell
يدعم Aspose.Cells عرض محتويات خلية ورقة العمل في شكل صورة. يمكنك ربط الصورة بالخلية التي تحتوي على البيانات التي تريد عرضها. نظرًا لأن الخلية أو نطاق الخلية مرتبط بكائن رسومي ، تظهر التغييرات التي يتم إجراؤها على البيانات تلقائيًا في الكائن الرسومي. أضف صورة إلى ورقة العمل عن طريق استدعاءإضافة الصورة طريقة الShapeCollection مجموعة (مغلفة في ملفورقة عمل موضوع). حدد نطاق الخلايا باستخداممجموعة الصيغة طريقةصورةموضوع.
يوجد أدناه لقطة شاشة للملف الذي ينشئه الكود أدناه.
إدراج صورة بناءً على مرجع الخلية
عينة من الرموز
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 | |
String dataDir = Utils.getDataDir(InsertPictureCellReference.class); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet's cells collection | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Add string values to the cells | |
cells.get("A1").putValue("A1"); | |
cells.get("C10").putValue("C10"); | |
// Add a blank picture to the D1 cell | |
Picture pic = (Picture) workbook.getWorksheets().get(0).getShapes().addPicture(0, 3, null, 10, 10); | |
// Set the size of the picture. | |
pic.setHeightCM(4.48); | |
pic.setWidthCM(5.28); | |
// Specify the formula that refers to the source range of cells | |
pic.setFormula("A1:C10"); | |
// Update the shapes selected value in the worksheet | |
workbook.getWorksheets().get(0).getShapes().updateSelectedValue(); | |
// Save the Excel file. | |
workbook.save(dataDir + "referencedpicture.xlsx"); |