# Importing xlrd library for reading Excel files

**URL:** <https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [November 22, 2021, 12:07pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332 "2021-11-22T12:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![g.cascales](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@g.cascales](https://forum.inductiveautomation.com/u/g.cascales)\
**Post date:** [November 22, 2021, 12:07pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332/1 "2021-11-22T12:07:57Z")

</div>

Hi all!

After reading and trying different solutions from the forum I am unable to do the following:

- I have an Excel file (with only one sheet) I want to read using an external python library (i.e. xlrd) and write the contents of that sheet into a dataset memory tag.

I have tried with this example and some other posts on the forum: [Microsoft excel 2010 - #2 by bkarabinchak.psi](https://forum.inductiveautomation.com/t/microsoft-excel-2010/32259/2)  
[Ignition 8.1: Excel Import & Export tool for Ignition Tags - #8 by pturmel](https://forum.inductiveautomation.com/t/ignition-8-1-excel-import-export-tool-for-ignition-tags/41485/8)

I copied the xlrd folder under both the “\user-lib\pylib\site-packages” and “\user-lib\pylib”:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9cafc3276357ca5535678745c43488a567a30968.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f03cc95cd45e75ed62590cccc7f7f9503bd6209.png)

I have a perspective view with a button and a label and the code is:

`
import xlrd
location = “C:\Users\GENIOTIC\Desktop\PruebasIgnition\PruebaExcel.xls”	
book = xlrd.open_workbook(location)
self.getSibling(“Label”).props.text = book.nsheets
`

Ignition version is 8.1.

Could anyone give me a tip here? I already tried clearing the cache and restarting the gateway.

In the newer versions of xlrd, it is possible to read “.xlsx” files?

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 22, 2021, 12:24pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332/2 "2021-11-22T12:24:40Z")

</div>

seems you might want to take an older version of xlrd

what is the error you are getting tho?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 22, 2021, 12:42pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332/3 "2021-11-22T12:42:23Z")

</div>

Consider not using xlrd at all. Ignition 8.1 includes the Apache POI libraries, which are native java tools for MS office documents. This topic covers the basics:

> [@Copying a Excel file to a tables Dataset](https://forum.inductiveautomation.com/t/copying-a-excel-file-to-a-tables-dataset/34942):
>
> Is there a easy way to copy a Excel File to a tables Dataset?

---

<div class="post-metadata">

**Author:** ![g.cascales](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@g.cascales](https://forum.inductiveautomation.com/u/g.cascales)\
**Post date:** [November 22, 2021, 2:59pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332/4 "2021-11-22T14:59:51Z")

</div>

Dear all,

I used this solution as indicated by @pturmel

> [@Copying an Excel file to a table's dataset](https://forum.inductiveautomation.com/t/copying-a-excel-file-to-a-tables-dataset/34942/13):
>
> Got my paperwork done early, so here's a sample to read from an Excel file EDIT: Reworked a bit to work with both .xls and .xlsx files EDIT: Modified to properly cast data types EDIT: Added handler for formula cell types EDIT: Added parameters to optionally specify sheet, row, and column numbers Reading back a file created from my other example: def excelToDataSet(fileName, hasHeaders = False, sheetNum = 0, firstRow = None, lastRow = None, firstCol = None, lastCol = None): import org.apac…

Works as I expected.

Thanks!!!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 22, 2021, 3:09pm UTC](https://forum.inductiveautomation.com/t/importing-xlrd-library-for-reading-excel-files/53332/5 "2021-11-22T15:09:11Z")

</div>

Kudos to @JordanCClark for excellent examples.
