xlrd

How to get Excel cell properties in Python

强颜欢笑 提交于 2019-11-27 23:13:29
Actually I am using xlrd module 0.8 version, but I don't know how to read cell properties like background color, font, and whether cell is locked. I tried to use import xlrd wb = xlrd.open_workbook(...) sh = wb.sheet_by_index(...) sh.sh._cell_xf_indexes(2, 2) It raises an error saying formatting information needs to be set while reading wb , but if I had that parameter then it shows it is still not implemented. Is there another module or how can this module itself be made to read cell properties? The following works for me, using xlrd version 0.7.6: from xlrd import open_workbook wb = open

xpython操作excel之xlwt与xlrd

别来无恙 提交于 2019-11-27 21:38:51
基于rest_framework框架的二进制流数据传输(提供较大文件的下载)   (1)数据源:     高质量图片、视频、音频、文件、数据库数据等。如果是数据库文件,需要先读取相应的数据,然后写入表格在传输到前端以供下载!   (2)数据读取:     利用yield函数生成器进行rb模式文件读取操作   (3)数据传输:     通过StreamingHttpResponse()二进制流格式进行相应(from django.http.response import StreamingHttpResponse)   如果除数中使用的有中文,需要通过quote()方法来确保中文不乱码(from urllib.parse import quote) 文件的上传见< Django之AJAX文件上传 >篇,python操作excel表格见< python操作excel----openpyxl模块 >或< xpython操作excel之xlwt与xlrd > drf接口模式提供唯一码的下载案例    1 import os 2 import openpyxl 3 from rest_framework.views import APIView 4 from django.http.response import StreamingHttpResponse 5 from urllib

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

时光毁灭记忆、已成空白 提交于 2019-11-27 21:31:05
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 prepare a script to generate a file having all the values in excel file separated by a pipe but this date thing is creating problem. Excel stores dates as floats. If you want to convert them xlrd has a function to help you with this: xldate_as_tuple An exmple: import datetime, xlrd book = xlrd.open_workbook("myfile.xls") sh = book.sheet_by_index(0) a1 =

GroupBy results to dictionary of lists

微笑、不失礼 提交于 2019-11-27 20:33:51
I have an excel sheet that looks like so: Column1 Column2 Column3 0 23 1 1 5 2 1 2 3 1 19 5 2 56 1 2 22 2 3 2 4 3 14 5 4 59 1 5 44 1 5 1 2 5 87 3 And I'm looking to extract that data, group it by column 1, and add it to a dictionary so it appears like this: {0: [1], 1: [2,3,5], 2: [1,2], 3: [4,5], 4: [1], 5: [1,2,3]} This is my code so far excel = pandas.read_excel(r"e:\test_data.xlsx", sheetname='mySheet', parse_cols'A,C') myTable = excel.groupby("Column1").groups print myTable However, my output looks like this: {0: [0L], 1: [1L, 2L, 3L], 2: [4L, 5L], 3: [6L, 7L], 4: [8L], 5: [9L, 10L, 11L]}

error: could not create '/Library/Python/2.7/site-packages/xlrd': Permission denied

三世轮回 提交于 2019-11-27 20:02:06
问题 I'm trying to install xlrd on mac 10.8.4 to be able to read excel files through python. I have followed the instructions on http://www.simplistix.co.uk/presentations/python-excel.pdf I did this: unzipped the folder to desktop in terminal, cd to the unzipped folder $ python setup.py install This is what I get: running install running build running build_py creating build creating build/lib creating build/lib/xlrd copying xlrd/__init__.py -> build/lib/xlrd copying xlrd/biffh.py -> build/lib

Identifying Excel Sheet cell color code using XLRD package

筅森魡賤 提交于 2019-11-27 19:42:44
I am writing a python script to read data from an excel sheet using xlrd . Few of the cells of the the work sheet are highlighted with different color and I want to identify the color code of the cell. Is there any way to do that ? An example would be really appreciated. JMax Here is one way to handle this: import xlrd book = xlrd.open_workbook("sample.xls", formatting_info=True) sheets = book.sheet_names() print "sheets are:", sheets for index, sh in enumerate(sheets): sheet = book.sheet_by_index(index) print "Sheet:", sheet.name rows, cols = sheet.nrows, sheet.ncols print "Number of rows: %s

Python xlrd.Book: how to close the files?

拟墨画扇 提交于 2019-11-27 17:58:07
问题 I read 150 excel files in a loop, opening them with xlrd.open_workbook() , which returns a Book object. At the end, when I tried to umount the volume, I was unable, and when I checked with lsof , I found that 6 of the files were still open: $ lsof | grep volumename python2 32349 deeenes mem REG 0,40 138240 181517 /.../150119.xls python2 32349 deeenes mem REG 0,40 135168 181482 /.../150609.xls python2 32349 deeenes mem REG 0,40 140800 181495 /.../140828.xls python2 32349 deeenes 5r REG 0,40

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

落爺英雄遲暮 提交于 2019-11-27 15:32:08
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):", book.sheet_names() print sh = book.sheet_by_index(0) print sh.name, sh.nrows, sh.ncols print print "Cell D30 is", sh.cell_value(rowx=29, colx=3) print for rx in range(5): print sh.row(rx) print It prints out this error raise XLRDError('Unsupported format, or corrupt file: ' + msg) xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '

python: update dataframe to existing excel sheet without overwriting contents on the same sheet and other sheets

冷暖自知 提交于 2019-11-27 15:25:53
问题 Struggling for this for hours so I decided to ask for help from experts here: I want to modify existing excel sheet without overwriting content. I have other sheets in this excel file and I don't want to impact other sheets. I've created sample code, not sure how to add the second sheet that I want to keep though. t=pd.date_range('2004-01-31', freq='M', periods=4) first=pd.DataFrame({'A':[1,1,1,1], 'B':[2,2,2,2]}, index=t) first.index=first.index.strftime('%Y-%m-%d') writer=pd.ExcelWriter(

Integers from excel files become floats?

守給你的承諾、 提交于 2019-11-27 14:23:20
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 back to 63 . Looking at the different cell types in the documentation , it seems that there isn't any integer type for cells, they're just floats. Hence, that's the reason you're getting floats back even when you wrote an integer. To convert a float to an integer just use int : >>> int(63.0) 63 >>> int(sheet.row(1)[0].value) 63 Excel treats all