xlrd

Reading a cell value that contains a formula returns 0.0 when using xlrd

老子叫甜甜 提交于 2020-01-12 14:01:30
问题 I try to read a cell value, say E5 and E5 in the excel sheet contains a formula ' =(A29 - A2) '. I use the following code and it returns me 0.00 instead of the actual value 1.440408 . Is there a way to solve this? I want to print the correct value. Please help me with this. Thank you. book = xlrd.open_workbook('Test.xlsx') first_sheet = book.sheet_by_index(0) particular_cell_value = (first_sheet.cell_value(4,4)) print(particular_cell_value) 回答1: Excel files store formulas and values

Reading a cell value that contains a formula returns 0.0 when using xlrd

旧巷老猫 提交于 2020-01-12 14:01:30
问题 I try to read a cell value, say E5 and E5 in the excel sheet contains a formula ' =(A29 - A2) '. I use the following code and it returns me 0.00 instead of the actual value 1.440408 . Is there a way to solve this? I want to print the correct value. Please help me with this. Thank you. book = xlrd.open_workbook('Test.xlsx') first_sheet = book.sheet_by_index(0) particular_cell_value = (first_sheet.cell_value(4,4)) print(particular_cell_value) 回答1: Excel files store formulas and values

Converting a Python Float to a String without losing precision

为君一笑 提交于 2020-01-11 16:39:38
问题 I am maintaining a Python script that uses xlrd to retrieve values from Excel spreadsheets, and then do various things with them. Some of the cells in the spreadsheet are high-precision numbers, and they must remain as such. When retrieving the values of one of these cells, xlrd gives me a float such as 0.38288746115497402. However, I need to get this value into a string later on in the code. Doing either str(value) or unicode(value) will return something like "0.382887461155". The

Converting a Python Float to a String without losing precision

北慕城南 提交于 2020-01-11 16:39:06
问题 I am maintaining a Python script that uses xlrd to retrieve values from Excel spreadsheets, and then do various things with them. Some of the cells in the spreadsheet are high-precision numbers, and they must remain as such. When retrieving the values of one of these cells, xlrd gives me a float such as 0.38288746115497402. However, I need to get this value into a string later on in the code. Doing either str(value) or unicode(value) will return something like "0.382887461155". The

Compare lists in python while looping

无人久伴 提交于 2020-01-11 11:01:51
问题 I have a script which I'm using to read an excel file and update an SQL database. I'm reading the excel file every 30 seconds using a loop. However I only want to update the database when the excel file changes If I use the != operator when the loop cycles it refreshes the value of 'temp' and thus does not register that the value is the same. Does anyone have an idea how to solve this problem..? Thanks! edit: updated to make my problem more clear! def update(): threading.Timer(1, update)

操作execl表格---xlrd,xlutils

邮差的信 提交于 2020-01-07 21:22:56
xlrd模块 1、xlrd模块介绍 读取Excel表格数据; 支付xlsx和xls格式的表格数据 安装方式:pip install xrld 导入模块:import xlrd 2、操作方法: 读取Excel表格 xlrd.open_workbook(filename)  参数filename需要打开的表格路径文件 获取sheet内容,索引从sheetx开始 execl.sheet_by_index(self,sheet) 参数sheet表示从参数开始 获取表格行数  nrows   获取表格列数  ncols 获取表格每行内容  get_rows() 获取表格每列内容  get_cols() 获取单元格数据内容 get_rows(row,cols).value import xlrd import time class ReadExcle(object): def __init__(self,file_name=None,index=None): if file_name==None: self.file_name=r'F:\项目\京东登陆\Testcfg\测试数据.xls' else: self.file_name = file_name if index==None: index=0 # 打开Excel表格 self.excel = xlrd.open_workbook

用python抓取“3d”彩票数据,怎么分析你说了算!

旧街凉风 提交于 2020-01-07 11:54:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 快下班了,正好准备去买彩票,就顺手写了2个脚本,一个用来下载最近的彩票数据,一个用来统计彩票数字,分享给大家! 彩票数据获取并写入excel表格 数据来源自己看吧~用外链通不过。。。 所用库:xlwt,requests,lxml 有几点需要注意的: 1、 构建列表 。因为存入excel文件的时候用的是列表,所以新建一个函数,分别取网页5个数据:时间、期数、开奖数123,然后每一页嵌套写入列表类似结构为[[时间、期数、开奖数1,2,3],[时间、期数、开奖数1,2,3]……],在循环页数,获取所有的数据!注意构建列表的形式和列表结果,这个在你写入表格的时候很重要! 2、 写入数据 。xlwt写入文件的方法为ws.write(行,列,数据),按行写入文件,所以新建一个变量line(代码第36行),每写入一行自增1。 其他方面都很简单,没有反爬,就是为了获取数据,好做分析! 最后excel表中的数据,是这样的: 最后大概有4840行数据,足够我们分析的了! 数据处理 用xlrd库就可以~话说xlwt库和xlrd库好像就是一个写数据,一个读数据。。。 就写了一个抓热门数字的,也就是取频率最高的。如果您有更好的想法或者玩法,可以自行去实现哦! 先读取数据,然后取到每一行的2.3.4列,每一列写入一个列表(现在有些后悔

用python统计3d彩票热门数据,看今天运势如何

≯℡__Kan透↙ 提交于 2020-01-07 06:47:57
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 快下班了,正好准备去买彩票,就顺手写了2个脚本,一个用来下载最近的彩票数据,一个用来统计彩票数字,分享给大家! 彩票数据获取并写入excel表格 数据来源自己看吧~用外链通不过。。。 所用库:xlwt,requests,lxml 有几点需要注意的: 1、构建列表。因为存入excel文件的时候用的是列表,所以新建一个函数,分别取网页5个数据:时间、期数、开奖数123,然后每一页嵌套写入列表类似结构为[[时间、期数、开奖数1,2,3],[时间、期数、开奖数1,2,3]……],在循环页数,获取所有的数据!注意构建列表的形式和列表结果,这个在你写入表格的时候很重要! 2、写入数据。xlwt写入文件的方法为ws.write(行,列,数据),按行写入文件,所以新建一个变量line(代码第36行),每写入一行自增1。 其他方面都很简单,没有反爬,就是为了获取数据,好做分析! 最后excel表中的数据 是这样的: 最后大概有4840行数据,足够我们分析的了! 数据处理 用xlrd库就可以~话说xlwt库和xlrd库好像就是一个写数据,一个读数据。。。 就写了一个抓热门数字的,也就是取频率最高的。如果您有更好的想法或者玩法,可以自行去实现哦! 先读取数据,然后取到每一行的2.3.4列,每一列写入一个列表(现在有些后悔

python xlrd,xlwt 读写excel文件

早过忘川 提交于 2020-01-05 02:07:31
python 读excel文件,需要xlrd库。下载地址: https://pypi.python.org/pypi/xlrd python 写excel文件,需要xlwt库。下载地址: https://pypi.python.org/pypi/xlwt/1.1.2 下载后修改扩展名为rar, 解压后安装: 安装成功后就可以引用了。如下代码: # -*- coding: utf-8 -*- import os import xlrd import xlwt import datetime ##################读excel文件############################## #打开Excel文件,参数:excelFile:Excel文件路径 def open_Excel(excelFile):   excelFile = unicode(excelFile, "utf8")   if os.path.isfile(excelFile):     try:       data = xlrd.open_workbook(excelFile)       return data     except Exception,e:       print str(e) '''往EXCEl单元格写内容,每次写一行sheet:页签名称;row:行内容列表

Using XLRD in Ironpython

自闭症网瘾萝莉.ら 提交于 2020-01-04 10:00:08
问题 I am trying to use the XLRD library in IronPython 2.7 At the most basic operation of opening an .xls file (2003 format) I get the following error, and I am not sure how to fix it: workbook = xlrd.open_workbook(xlsfile) File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\xlrd\__init__.py", line 426, in open_workbook TypeError: sequence item 0: expected bytes or byte array, str found any ideas? i would like to use xlrd if possible but seems like there may be some compatibility