xlrd

python xlrd receiving float from excel text cell

故事扮演 提交于 2019-12-05 08:27:55
I am attempting to read values from an Excel file using xlrd. It has been working great on dates, numbers, and up until now text. I have a column (category) with cells containing text (the cells are formatted as text). When I print out the cell value a float is displayed instead of the text. I also printed out the ctype of the Cell object(s) to check and it is showing as Number. I've read through the documentation and tutorial of xlrd and can't seem to find why this is occurring. Could it be that my excel file is somehow messed up? Any suggestions or pointers in the right direction? import

Can't get Excel drop-down list (combobox) value with python

妖精的绣舞 提交于 2019-12-04 22:55:22
I have an excel file with a drop-down list and I would like to access its current value from python. In vba the code is really simple : Sheets("name_of_my_sheet").name_of_my_list.value I looked for an equivalent in xlrd but couldn't find one. I got my answer. The list the drop-down box is created at run time in vba so you can't "read" its value from the xls. The solution is to write in VBA an on change method that will actually write the value to the cell under the box. Sub My_List_Change() Sheets("Containing your box").Cells(x,y) = My_List.value // x,y being the coordinates of the cell hidden

Python Xlrd and Xlwt

一笑奈何 提交于 2019-12-04 20:53:56
I have the following content in an old Excel sheet: I need to generate a new Excel sheet with the following values: In the input Excel file's 3rd column I have a range 10010-10040 and an increment value of 10 . This needs to be expanded in my new Excel file. If I give a comma (,) in between values, it should be treated as separate values and expanded. (Like in row2, column 3) I have no idea how to do this and I am new to Python. Try the following. This uses the xlrd and xlwt libraries to read and write xls spreadsheets: import xlrd import xlwt wb_in = xlrd.open_workbook(r'input.xls') sheet

python : Get Active Sheet in xlrd? and help for reading and validating excel file in Python

痞子三分冷 提交于 2019-12-04 18:16:18
2 Questions to ask: Ques 1: I just started studying about xlrd for reading excel file in python. I was wondering if there is a method in xlsrd --> similar to get_active_sheet() in openpyxl or any other way to get the Active sheet ? get_active_sheet() works this in openpyxl import openpyxl wb = openpyxl.load_workbook('example.xlsx') active_sheet = wb.get_active_sheet() output : Worksheet "Sheet1" I had found methods in xlrd for retrieving the names of sheets, but none of them could tell me the active sheet. Ques 2: Is xlrd the best packaage in python for reading excel files? I also came across

xlrd/xlwt

為{幸葍}努か 提交于 2019-12-04 17:20:21
开始使用xlrd,下载安装包,解压,安装省略 下载 http://pypi.python.org/pypi/xlrd 假设我的表格文件叫demo.xls,三个sheet,第一个sheet内容如下 则要访问3行第D列单元格则使用如下代码 ---------------------------------------------------------------------------- >>> import xlrd >>> import os >>> import sys >>> wb=xlrd.open_workbook("demo.xls") >>> range(wb.nsheets) #可以看到,一共有三个sheet,其索引为0,1,2 [0, 1, 2] >>> sht1=wb.sheet_by_name("demo_sheet1") #等同于使用sht2=wb.sheet_by_index(0) >>> print sht1.cell_value(2,3) #索引从0开始,先行,后列,D4对应与(2,3) 是 >>> print sht1.cell_value(4,1) #B5对应(4,1) 餐饮 >>> for item in sht1.row_values(1): #可以输出整个一行,返回为列表 print item, 4.0 电视剧 web 是 ========

python之xlrd模块

妖精的绣舞 提交于 2019-12-04 08:45:35
记录用xlrd模块分别读取单Sheet和多Sheet 1 import xlrd 2 3 '''读取单Sheet版 4 指定文件编码,读取Excel文件; 5 读取指定的某个Sheet所有内容并输出所有内容''' 6 xlrd.Book.encoding = 'utf-8' 7 rd = xlrd.open_workbook(r'C:\Users\Administrator\Documents\testdata.xls') 8 print(rd) 9 # print(rd.nsheets, type(rd.nsheets)) 10 sheet = rd.sheet_by_index(0) 11 print(rd.sheet_names()) 12 rows = sheet.nrows 13 for i in range(rows): 14 print(sheet.row_values(i)) 15 '''读取多Sheet版 16 读取文件的所有Sheet并输出所有内容''' 17 rd1 = xlrd.open_workbook(r'C:\Users\Administrator\Documents\testdata-release1.xls', formatting_info=True) 18 print(rd1) 19 # print(rd1.nsheets, type(rd1

python的xlwt和xlrd模块

别说谁变了你拦得住时间么 提交于 2019-12-04 08:41:26
xlrd模块 xlrd模块用于从excel中读取信息,例如.xls,.xlsx文件 1.读取到的数据 xlrd模块读取到的数据类型为列表,每一行为一个单独的列表 [[第一行],['第一列','第二列','第三列',...],[第三行]....] 如果有多个sheet,默认读到一个列表中 # 打开xls或xlsx文件,返回Book类文件 workbook = xlrd.open_workbook(filepath) # 返回工作簿中所有sheet的名字,存放在列表中 workbook.sheet_names() # 返回工作簿中所有sheet的索引,存放在列表中 workbook.sheets() # 根据sheet名读取相应sheet,返回该sheet中的内容 workbook.sheet_by_name() # 根据sheet索引读取相应sheet,返回该sheet中的内容 workbook.sheet_by_index() # 检查sheet是否导入成功,成功返回True,不成功返回False workbook.sheet_loaded()# 释放资源 workbook.release_resources() # 获取当前sheet中指定列中的内容 sheet.col_values() # 获取当前sheet中指定行中的内容 sheet.row_values() #

Dealing with Nested Loops in Python - Options?

放肆的年华 提交于 2019-12-04 06:18:18
问题 I have a function that looks like this (below). I'm using xlrd in python. Whenever I perform the "print path" function, I receive way too many iterations of path. Essentially, what I'm trying to do is compare two columns in excel, and print out a third. That works perfectly, except that the third is printed out too many times, and I believe the problem is the nested loops. def question(): for x in xrange(sheet.nrows): buddy = sheet.cell_value(x, 13) newton = buddy.split(',') james = sheet.col

how to open xlsx file with python 3

爱⌒轻易说出口 提交于 2019-12-04 05:59:05
I have an xlsx file with 1 sheet. I am trying to open it using python 3 (xlrd lib), but I get an empty file! I use this code: file_errors_location = "C:\\Users\\atheelm\\Documents\\python excel mission\\errors1.xlsx" workbook_errors = xlrd.open_workbook(file_errors_location) and I have no errors, but when I type: workbook_errors.nsheets I get "0", even the file has some sheets... when I type: workbook_errors I get: xlrd.book.Book object at 0x2.. any help? thanks You can use Pandas pandas.read_excel just like pandas.read_csv : import pandas as pd file_errors_location = 'C:\\Users\\atheelm\

Reading an Excel object retrieved using urllib2

穿精又带淫゛_ 提交于 2019-12-04 03:49:19
问题 I am getting an Excel file using urllib2 and saving into response below. I want to be able to process this excel file using xlrd or similar. I included some info below, let me know if I can provide more info. How can I have response object transformed into an object I can play with? response = <addinfourl at 199999998 whose fp = <socket._fileobject object at 0x100001010>> response.read() prints: '\xd0\xcf\x11\xe0...' Headers: Content-Type: application/vnd.ms-excel Transfer-Encoding: chunked