Infoga en bild baserat på cellreferens

Infoga en bild baserad på cellreferens

Aspose.Cells stöder att visa innehållet i en kalkylbladscell i en bildform. Du kan länka bilden till cellen som innehåller datan du vill visa. Eftersom cellen eller cellintervallet är länkad till den grafiska objektet visar ändringar som du gör i datan i den cellen eller cellintervallet automatiskt upp i det grafiska objektet. Lägg till en bild i kalkylbladet genom att använda AddPicture metoden i ShapeCollection samlingen (inkapslad i Worksheet objektet). Ange cellintervallet genom att använda Formula attributet i Picture objektet.

Kodexempel

// 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");
// Add a blank picture to the D1 cell
Picture pic = (Picture)workbook.Worksheets[0].Shapes.AddPicture(0, 3, 10, 6, null);
// 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");