Fügen Sie ein Bild basierend auf der Referenz Cell ein

Einfügen eines Bildes basierend auf der Referenz Cell

Aspose.Cells unterstützt die Anzeige des Inhalts einer Arbeitsblattzelle in einer Bildform. Sie können das Bild mit der Zelle verknüpfen, die die Daten enthält, die Sie anzeigen möchten. Da die Zelle oder der Zellbereich mit dem Grafikobjekt verknüpft ist, werden Änderungen, die Sie an den Daten in dieser Zelle oder diesem Zellbereich vornehmen, automatisch im Grafikobjekt angezeigt. Fügen Sie dem Arbeitsblatt ein Bild hinzu, indem Sie die aufrufenBild hinzufügen Methode derShapeCollection Sammlung (eingekapselt in derArbeitsblatt Objekt). Geben Sie den Zellbereich mithilfe von anFormel Attribut derBildObjekt.

Codebeispiel

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a new Workbook
Workbook workbook = new Workbook();
// Get the first worksheet's cells collection
Cells cells = workbook.Worksheets[0].Cells;
// Add string values to the cells
cells["A1"].PutValue("A1");
cells["C10"].PutValue("C10");
// Get the conditional icon's image data
byte[] imagedata = ConditionalFormattingIcon.GetIconImageData(IconSetType.TrafficLights31, 0);
// Create a stream based on the image data
MemoryStream stream = new MemoryStream(imagedata);
// Add a blank picture to the D1 cell
Picture pic = (Picture)workbook.Worksheets[0].Shapes.AddPicture(0, 3, stream, 10, 10);
// Specify the formula that refers to the source range of cells
pic.Formula = "A1:C10";
// Update the shapes selected value in the worksheet
workbook.Worksheets[0].Shapes.UpdateSelectedValue();
// Save the Excel file.
workbook.Save(dataDir + "referencedpicture.out.xlsx");