easyexcel支持文档文件的嵌入吗,不是以文档超链接的方式,而是直接嵌入可点击的方式,是否有相关的API可以提供,谢谢
e7arh2l61#
import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileOutputStream; import java.io.IOException; public class EmbedDocumentInExcel { public static void main(String[] args) throws IOException { Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Document"); // 创建一个超链接 CreationHelper creationHelper = workbook.getCreationHelper(); Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.FILE); hyperlink.setAddress("path/to/your/document.docx"); // 在单元格中插入超链接 Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue("Click to open document"); cell.setHyperlink(hyperlink); // 保存 Excel 文件 try (FileOutputStream fileOut = new FileOutputStream("embedded_document.xlsx")) { workbook.write(fileOut); } // 关闭工作簿 workbook.close(); } }
1条答案
按热度按时间e7arh2l61#