在 Cell 中添加 HTML 富文本
Contents
[
Hide
]
Aspose.Cells支持将面向Microsoft Excel的HTML转换为XLS/XLSX格式。这意味着,Microsoft Excel生成的HTML可以使用Aspose.Cells转换回XLS/XLSX格式。
同样,如果有一些简单的HTML,Aspose.Cells可以将其转换为HTML Rich Text。 Aspose.Cells提供Cell.setHtmlString()属性可以采用这样一个简单的 HTML 并将其转换为格式化的单元格文本。
例子
以下屏幕截图显示了使用 Aspose.Cells 生成的输出 Excel 文件。如您所见,它显示了使用Cell.setHtmlString()财产。
这是生成输出 Excel 文件的示例代码,如上面的屏幕截图所示。
This file contains hidden or 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 | |
String dataDir = Utils.getDataDir(AddImageHyperlinks.class); | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Insert a string value to a cell | |
worksheet.getCells().get("C2").setValue("Image Hyperlink"); | |
// Set the 4th row height | |
worksheet.getCells().setRowHeight(3, 100); | |
// Set the C column width | |
worksheet.getCells().setColumnWidth(2, 21); | |
// Add a picture to the C4 cell | |
int index = worksheet.getPictures().add(3, 2, 4, 3, dataDir + "aspose-logo.jpg"); | |
// Get the picture object | |
com.aspose.cells.Picture pic = worksheet.getPictures().get(index); | |
// Set the placement type | |
pic.setPlacement(PlacementType.FREE_FLOATING); | |
// Add an image hyperlink | |
pic.addHyperlink("http://www.aspose.com/"); | |
com.aspose.cells.Hyperlink hlink = pic.getHyperlink(); | |
// Specify the screen tip | |
hlink.setScreenTip("Click to go to Aspose site"); | |
// Save the Excel file | |
workbook.save(dataDir + "ImageHyperlink.xls"); |