Reading excel files

daniel-REC
2012-11-26
2012-11-26
  • daniel-REC - 2012-11-26

    Hello,

    Do someone know how to install package from this site: http://www.python-excel.org/ to CoDeSys? I wan to use excel file to read some variables into the python script.

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    Hi,

    I did not try this myself, but I guess it should just work to unpack the module directories to some common parent directory, and then add that directory to sys.path from within the python script. Alternatively, you could try to copy the directories to the ScriptLib subdirectory ouf your CODESYS installation.

    HTH,
    Markus Schaber

     
  • daniel-REC - 2012-11-26

    Hi,

    I did copy the package directories to CoDeSys \ScriptLib directory, but there is still an error while trying to run the script. This is the example:

    from xlrd import open_workbook
    proj = projects.primary
    app = proj.active_application
    onlineapp = online.create_online_application(app)
    temp = xlrd.open_workbook('test.xlsx')
    

    And the error message is:
    Cannot import name nested_scopes

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    Hmm, strange...

    nested_scopes is a "from future" special feature. It should work with IronPython, too.

    I'll try to find some time to look into that issue, but for diagnostic purposes, could you try to check whether it works with plain IronPython?

    Thanks,
    Markus

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    Hi,

    I just did see that your example code does the import the wrong way:

    If you use "from xlrd import open_workbook", then you need to use "temp = open_workbook(...)" below.

    http://pypi.python.org/pypi/xlutils.

     
  • daniel-REC - 2012-11-26

    Still, none of this works:(

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    Hi, Daniel,

    I did solve the problem: It seems that the future.py we deliver with CODESYS is an outdated version, it is fixed in recent IronPython versions (2.7.3 has the fix).

    If you copy the attached future.py CODESYS scriptlib/ directory, it should work. (It did work on my machine with V3.5 SP1 Patch 4).

    The future.py file is from IronPython 2.7.3, and it is identical to the one from cPython (ActivePython 2.7.2.4). There's a Thread on the mailing list covering that subject.

    I did open CDS-31786: ScriptEngine: nested scopes don't work, feel free to add yourself as an interested customer via your support contact.

    HTH,
    Markus

    future.zip [1.65 KiB]

     
  • daniel-REC - 2012-11-26

    Thank You for reply.
    Can You also check the attachment, because when I try to download it there's a message "file not found"?

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    I can download it from the internal network, but not externally (with my smartphone). I'll contact our admins...

    the IronPython Github repository (use the "RAW" button on that page).

     
  • daniel-REC - 2012-11-26

    It's like never ending errors:)
    After Your tip and trying to execute I have another error message: 'LightException' object has no attribute 'etree'.
    In IronPython this is working.

     
  • Anonymous - 2012-11-26

    Originally created by: M.Schaber

    Just for the record: It seems that import of xsl files works, but xlsx does not. I currently don't know how to fix that problem, my guess is that it might work once we update the IronPython version delivered with CODESYS.

     

Log in to post a comment.