Pip install openpyxl - error

How to install openpyxl in ignition?

i can't able install

can any one help me out

Here is the guide for Importing and using 3rd party Python libraries in Ignition – Inductive Automation Help Center

2 Likes


its there but
from openpyxl import Workbook

error
ImportError: No module named openpyxl

Try

from openpyxl import workbook

Remember case matters in Python

1 Like

from openpyxl import workbook

same error
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named openpyxl

Did you restart the designer?

Also, there is already the Apache POI libraries installed. Why not use them?

2 Likes

yes restarted still same error

ask me to call like this

from openpyxl import Workbook
import Workbook

tired both same error

ok understood

this is what i am trying to do

i have easy chart

Is it possible take a screenshot of easy chart and put it in excel sheet automatically

any idea?

You will find this system.print.printToImage - Ignition User Manual 8.1 - Ignition Documentation

and this

Helpful, but no one here is or can code it for you. Give it your best shot and if you get errors feel free to ask about them but these two should get you started.

The above is assuming if you're using Vision. If you're using perspective - I don't know that you can take screenshots, but maybe someone else can chime in.

1 Like


Script on the button. I'd recommend breaking this out into a project script or two for use in production.

from java.awt.image import BufferedImage
from org.apache.poi.util import IOUtils
from javax.imageio import ImageIO
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 org.apache.poi.xssf.usermodel import XSSFClientAnchor
from org.apache.poi.ss.usermodel.ClientAnchor import AnchorType

from java.io import FileOutputStream, ByteArrayOutputStream

component = event.source.parent.getComponent('Easy Chart')

# Create a captrue of the component and get its byte array
image = BufferedImage(component.getWidth(),
                      component.getHeight(),
                      BufferedImage.TYPE_INT_RGB
                     )
component.paint(image.getGraphics())
baos = ByteArrayOutputStream()
ImageIO.write(image, 'png', baos)
imageBytes = baos.toByteArray()

# Create workbook
wb = XSSFWorkbook()

# Create Sheet
sheet = wb.createSheet('Easy Chart')

# Add the image to the workbook
imageId = wb.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG)

# Create the drawing patriarch. We need this to draw the image on the sheet.
drawing = sheet.createDrawingPatriarch()

# Create an anchor. The anchor is where the image will go.
anchor = XSSFClientAnchor()
anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE)
# set anchor location to B2
anchor.setCol1(1)
anchor.setRow1(1)

# Draw the image and return the picture object
picture = drawing.createPicture(anchor, imageId)
# Put the picture back to it's orignal size
picture.resize()

# Write the excel file
output = FileOutputStream('c:/test/easyChart.xlsx')
wb.write(output)
output.close()
3 Likes

Couldn't help yourself huh? lol. I think here -

image = BufferedImage(component.getWidth(),
                      component.getHeight(),
                      BufferedImage.TYPE_INT_RGB
                     )

you may be able to use system.print.createImage, feed a component get a BufferedImage of it back, but it's not saving you much code wise and you may want the ability to specify height/width manually.

2 Likes

Had a quiet moment between meetings. And, I'm all about dat flexibity.

2 Likes

Now lets just hope he is using vision!

The OP called out the Easy Chart.

1 Like

Yes i am using vision