The grammar is a bit confusing, but I assume you want to put an image into an Excel file.
Consider using Apache POI instead.
Example usable in the Script console:
from org.apache.poi.ss.usermodel import Cell
from org.apache.poi.ss.usermodel import Row
from org.apache.poi.ss.usermodel import Sheet
from org.apache.poi.ss.usermodel import Workbook
from org.apache.poi.xssf.usermodel import XSSFWorkbook
from org.apache.poi.xssf.usermodel import XSSFDataFormat
from java.io import FileOutputStream, ByteArrayOutputStream
from java.io import FileInputStream, ByteArrayInputStream
from org.apache.commons.io import IOUtils
imagePath = '/home/jordanc/Desktop/IA_Logo_out.png'
excelPath = '/home/jordanc/Desktop/IA_Logo.xlsx'
wb = XSSFWorkbook()
sheet = wb.createSheet('Image Example')
inputStream = FileInputStream(imagePath)
bytes = IOUtils.toByteArray(inputStream)
inputStream.close()
imageIndex = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG)
helper = wb.getCreationHelper()
drawing = sheet.createDrawingPatriarch()
anchor = helper.createClientAnchor()
anchor.setCol1(1)
anchor.setRow1(2)
image = drawing.createPicture(anchor, imageIndex)
image.resize()
fileOut = FileOutputStream(excelPath)
wb.write(fileOut)
fileOut.close()
Other examples are on the forum for writing datasets to Excel, if you are looking to do that, as well.
Note that the example uses FileInputStream/FleOutputStream because it's using files for incoming and outgoing data. In Perspective you will use ByteArrayInputStream/ByteArrayOutputStream.
3 Likes