Infoga en bild baserad på cellreferens
Infoga en bild baserad på cellreferens
Aspose.Cells stöder visning av innehållet i en kalkylblads cell i en bildform. Du kan länka bilden till cellen som innehåller data som du vill visa. Eftersom cellen eller cellintervallet är länkat till den grafiska objektet, visas ändringar av datat automatiskt i grafikobjektet. Lägg till en bild till kalkylbladet genom att använda addPicture-metoden av ShapeCollection-samlingen (inkapslad i Worksheet-objektet). Ange cellintervallet genom att använda setFormula-metoden av Picture-objektet.
Nedan finns en skärmbild på filen som koden nedan genererar.
Infogar en bild baserat på cellreferens
Exempelkod
// 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"); |