翻譯|使用教程|編輯:李顯亮|2021-05-11 09:48:05.000|閱讀 220 次
概述:本文將向您展示如何使用Spire.XLS for Java將圖像注釋插入Excel。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.XLS for Java是專業(yè)的Java Excel API,使開發(fā)人員無需使用Microsoft Office或Microsoft Excel即可創(chuàng)建,管理,操作,轉(zhuǎn)換和打印Excel工作表。
之前已經(jīng)演示了如何在Java應(yīng)用程序的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); } }
輸出結(jié)果:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn