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 det grafiska objektet, visas ändringar av data automatiskt i det grafiska objektet. Lägg till en bild i arbetsbladet genom att ringaaddPicture metod förShapeCollection samling (inkapslad iArbetsblad objekt). Ange cellintervallet med hjälp avsetFormula metod förBildobjekt.
Nedan är en skärmdump av filen som koden nedan genererar.
Infoga en bild baserad på cellreferens
Exempelkod
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"); |