Infoga en bild baserat på Cell referens
Contents
[
Hide
]
Ibland har du en tom bild och behöver visa data eller innehåll i bilden genom att ställa in en cellreferens i formelfältet. Aspose.Cells stöder den här funktionen (Microsoft Excel 2010).
Infoga en bild baserat på Cell referens
Aspose.Cells stöder visning av innehållet i en kalkylbladscell i en bildform. Du kan länka bilden till cellen som innehåller data som du vill visa. Eftersom cellen eller cellområdet är länkat till grafikobjektet, visas ändringar som du gör i data i den cellen eller cellområdet automatiskt i grafikobjektet. Lägg till en bild i arbetsbladet genom att ringaLägg till bild metod förShapeCollection samling (inkapslad iArbetsblad objekt). Ange cellintervallet med hjälp avFormel attribut avBildobjekt.
Kodexempel
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-.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"); |