国产Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中将图像注释添加到Excel

本文将向您展示如何使用Spire.XLS for Java将图像注释插入Excel。

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,立即购买!想要获取更多福利的朋友可以咨询在线客服哦~


代码如下:

import com.spire.xls.*;import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.*;public class Test {    public static void main(String[] args)throws IOException {        //Load the sample Excel file        Workbook workbook = new Workbook();        workbook.loadFromFile("Sample.xlsx");        //Get the first worksheet        Worksheet sheet = workbook.getWorksheets().get(0);        //set the font        ExcelFont font = workbook.createFont();        font.setFontName("Arial");        font.setSize(11);        font.setKnownColor(ExcelColors.Orange);        CellRange range = sheet.getCellRange("D1");        //Add the commet        ExcelComment comment = range.addComment();        //Load the image        BufferedImage bufferedImage = ImageIO.read(new File("Logo.jpg"));        //Use the image to fill the comment        comment.getFill().customPicture(bufferedImage, "Logo.jpg");        //Set the height and width for the comment        comment.setHeight(bufferedImage.getHeight());        comment.setWidth(bufferedImage.getWidth());        //Show the comment        comment.setVisible(true);        //Save the document to file        workbook.saveToFile("output/setimageComment.xlsx", ExcelVersion.Version2013);    }}

输出结果:

国产Excel开发组件Spire.XLS教程:在Java中以编程方式在Excel中将图像注释添加到Excel


是E-iceblue官方友好合作伙伴,如果您对spire.xls可以联系在线客服了解具体授权价格和使用机制

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年4月8日
下一篇 2021年4月8日

相关推荐

发表回复

登录后才能评论