从网址插入链接图片
Contents
[
Hide
]
有时您需要将来自网络 (http://) 的图片插入到工作表中。为此,请指定图片的 URL,每次在 Microsoft Excel 中打开电子表格时都会下载图片。该图像并未物理嵌入到 Excel 文档中,而是指向 Web 资源。
从网址插入链接图片
使用 Microsoft Excel
在 Microsoft Excel 中(例如 2007):
- 点击插入菜单并选择图片.
- 在“插入图片”对话框中指定图片的网址。
图像被插入。
使用 Aspose.Cells for Java
Aspose.Cells for Java 支持使用方法添加链接图片ShapeCollection.addLinkedPicture(int upperLeftRow, int upperLeftColumn, int height, int width, java.lang.String sourceFullName).
该方法返回一个图片目的。
以下示例显示如何将网址中的链接图片添加到工作表。
运行代码后,生成的 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"); |