从Web地址插入链接图片
Contents
[
Hide
]
有时您需要从Web(http://)将图片插入工作表中。为此,指定图片的URL,每次在Microsoft Excel中打开电子表格时都会下载图片。该图像并没有实际嵌入到Excel文档中,而是指向Web资源。
从网址插入链接图片
使用Microsoft Excel
在Microsoft Excel中(例如2007):
- 单击插入菜单,然后选择图片。
- 在插入图片对话框中指定图片的Web地址。
图片已插入。
使用Aspose.Cells for Java
Aspose.Cells for Java支持使用 ShapeCollection.addLinkedPicture(int upperLeftRow, int upperLeftColumn, int height, int width, java.lang.String sourceFullName) 方法添加连接的图像。
该方法返回一个Picture对象。
下面的示例显示了如何将来自Web地址的链接图片添加到工作表中。
运行代码后,生成的Excel文件在第一个工作表上包含一个链接图片。
输出文件
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(InsertLinkedPicturefromWebAddress.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Insert a linked picture (from Web Address) to B2 Cell. | |
Picture pic = (Picture) workbook.getWorksheets().get(0).getShapes().addLinkedPicture(1, 1, 100, 100, | |
"http://www.aspose.com/Images/aspose-logo.jpg"); | |
// Set the source of the inserted image. | |
pic.setSourceFullName("http://www.aspose.com/images/aspose-logo.gif"); | |
// Set the height and width of the inserted image. | |
pic.setHeightInch(1.04); | |
pic.setWidthInch(2.6); | |
// Save the Excel file. | |
workbook.save(dataDir + "LinkedPicture.xlsx"); |