Questions tagged [xlrd]

xlrd is a python library to extract data from Microsoft Excel spreadsheet files

xlrd is a python library to extract data from Microsoft Excel spreadsheet files.

xlrd can extract data from Excel spreadsheets (.xls and .xlsx, versions 2.0 onwards) on any platform, is written in pure Python and is Unicode-aware.

1366 questions
31
votes
1 answer

Using Python, write an Excel file with columns copied from another Excel file

I have an Excel file containing a varying number of columns, I would like to loop through certain columns (from their header row value) of that file using Python, then write (copy) those columns to another Excel file. Any examples on how I can do…
salamey
  • 3,633
  • 10
  • 38
  • 71
30
votes
3 answers

Reading Excel file is magnitudes slower using openpyxl compared to xlrd

I have an Excel spreadsheet that I need to import into SQL Server on a daily basis. The spreadsheet will contain around 250,000 rows across around 50 columns. I have tested both using openpyxl and xlrd using nearly identical code. Here's the code…
Ron Johnson
  • 303
  • 1
  • 3
  • 7
29
votes
7 answers

Get formula from Excel cell with python xlrd

I have to port an algorithm from an Excel sheet to python code but I have to reverse engineer the algorithm from the Excel file. The Excel sheet is quite complicated, it contains many cells in which there are formulas that refer to other cells (that…
alexroat
  • 1,687
  • 3
  • 23
  • 34
29
votes
2 answers

Convert date from excel in number format to date format python

I am reading data from excel and manipulating the data using python. But dates are coming as integers. How can I convert the dates back to date format? 5/15/2015 is coming as 42139.00
user2728024
  • 1,496
  • 8
  • 23
  • 39
28
votes
1 answer

Django and xlrd, reading from memory

My plan is to let a user to upload an excel file, once uploaded I will be displaying editable form which contains the content of the uploaded excel, once user confirms the input is correct, he/she hits the save button and these items are saved at…
Hellnar
  • 62,315
  • 79
  • 204
  • 279
28
votes
6 answers

XLRD/Python: Reading Excel file into dict with for-loops

I'm looking to read in an Excel workbook with 15 fields and about 2000 rows, and convert each row to a dictionary in Python. I then want to append each dictionary to a list. I'd like each field in the top row of the workbook to be a key within each…
kylerthecreator
  • 1,509
  • 3
  • 15
  • 32
28
votes
1 answer

How to set NULL for IntegerField instead of setting 0?

I'm uploading some data from an excel file using xlrd and turning that data into models (with mainly IntegerField values) in Django. My excel file has a bunch of missing data. Unfortunately, these missing data are converted to the value of 0 in my…
jyli7
  • 2,731
  • 6
  • 23
  • 31
27
votes
5 answers

How to use ``xlrd.xldate_as_tuple()``

I am not quite sure how to use the following function: xlrd.xldate_as_tuple for the following data xldate:39274.0 xldate:39839.0 Could someone please give me an example on usage of the function for the data?
user428370
26
votes
2 answers

How to count the total number of sheets in an Excel file using Python

I am reading a excel file using python. import pandas as pd import os xls = pd.ExcelFile('D:\DirectoryProject\Mapping.xlsx') It has several number of data sheets which I don't know. How can I count the total number of sheets in Mapping.xlsx file…
user4444350
25
votes
9 answers

Error: Unsupported format, or corrupt file: Expected BOF record

I am trying to open a xlsx file and just print the contents of it. I keep running into this error: import xlrd book = xlrd.open_workbook("file.xlsx") print "The number of worksheets is", book.nsheets print "Worksheet name(s):",…
user2353003
  • 522
  • 1
  • 7
  • 18
25
votes
1 answer

Reading date as a string not float from excel using python xlrd

Possible Duplicate: How do I read a date in Excel format in Python? My date can be among any field in an excel file but when I read it using python xlrd its being read as a float. Is there a way to read all the excel cells as string? I want to…
Kundan Kumar
  • 1,974
  • 7
  • 32
  • 54
24
votes
10 answers

Python Creating Dictionary from excel data

I want to create a dictionary from the values, i get from excel cells, My code is below, wb = xlrd.open_workbook('foo.xls') sh = wb.sheet_by_index(2) for i in range(138): cell_value_class = sh.cell(i,2).value cell_value_id =…
tuna
  • 6,211
  • 11
  • 43
  • 63
23
votes
2 answers

Is there a way to close a workbook using xlrd

I am using the function open_workbook() to open an excel file. But I cannot find any function to close the file later in the xlrd module. Is there a way to close the xls file using xlrd? Or is not required at all?
Sumod
  • 3,806
  • 9
  • 50
  • 69
22
votes
6 answers

Integers from excel files become floats?

I use xlrd to read data from excel files. For integers stored in the files, let's say 63, the xlrd interprets it as 63.0 of type number. Why can't xlrd recognize 63 as an integer? Assume sheet.row(1)[0].value gives us 63.0. How can I convert it…
Terry Li
  • 16,870
  • 30
  • 89
  • 134
21
votes
1 answer

python xlutils : formatting_info=True not yet implemented

I've got simple code to copy files with xlutils, xlrd, xlwt (downloaded new libraries from python-excel.org) with not loosing formatting. I've got an error as below: from xlwt.Workbook import * from xlwt.Style import * from xlrd import…
user1891854
  • 211
  • 1
  • 2
  • 4
1
2
3
91 92