翻譯|使用教程|編輯:李顯亮|2021-05-07 10:14:07.727|閱讀 287 次
概述:本文將向您展示如何通過在Java應用程序中使用Spire.XLS在Excel工作表中將搜索的文本替換為圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.XLS for Java是專業的Java Excel API,使開發人員無需使用Microsoft Office或Microsoft Excel即可創建,管理,操作,轉換和打印Excel工作表。
本文將向您展示如何通過在Java應用程序中使用Spire.XLS在Excel工作表中將搜索的文本替換為圖像。
Excel范例:
import com.spire.xls.*; import java.io.IOException; public class replaceTextwithImage { public static void main(String[] args) throws IOException { //Load the sample Excel document Workbook workbook = new Workbook(); workbook.loadFromFile("Sample.xlsx"); //Get the first worksheet Worksheet worksheet = workbook.getWorksheets().get(0); //Find the text string {{Image}} CellRange[] ranges = worksheet.findAllString("{{Image}}", false, false); for (CellRange range : ranges) { //set the text as null range.setText(""); //get the row and column of the searched range int row = range.getRow(); int column = range.getColumn(); //Add the image to the searched range worksheet.getPictures().add(row, column, "logo.jpg", ImageFormatType.Jpeg); //Save the document to file workbook.saveToFile("replaceTextwithImage.xlsx", ExcelVersion.Version2013); } } }
效果圖:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn