根据Cell参考插入图片
Contents
[
Hide
]
有时您有一张空白图片,需要通过在公式栏中设置单元格引用来显示图片中的数据或内容。 Aspose.Cells 支持此功能 (Microsoft Excel 2010)。
根据Cell参考插入图片
Aspose.Cells 支持以图像形状显示工作表单元格的内容。您可以将图片链接到包含要显示的数据的单元格。由于单元格或单元格区域链接到图形对象,因此您对该单元格或单元格区域中的数据所做的更改会自动出现在图形对象中。通过调用将图片添加到工作表添加图片的方法形状集合集合(封装在工作表目的)。使用指定单元格范围公式的属性图片目的。
代码示例
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"); |