xlrd

How to sort Excel sheet using Python

限于喜欢 提交于 2019-12-21 20:48:42
问题 I am using Python 3.4 and xlrd. I want to sort the Excel sheet based on the primary column before processing it. Is there any library to perform this ? 回答1: There are a couple ways to do this. The first option is to utilize xlrd, as you have this tagged. The biggest downside to this is that it doesn't natively write to XLSX format. These examples use an excel document with this format: Utilizing xlrd and a few modifications from this answer: import xlwt from xlrd import open_workbook target

Python: xlrd discerning dates from floats

懵懂的女人 提交于 2019-12-21 09:34:46
问题 I wanted to import a file containing text, numbers and dates using xlrd on Python. I tried something like: if "/" in worksheet.cell_value: do_this else: do_that But that was of no use as I latter discovered dates are stored as floats, not strings. To convert them to datetime type I did: try: get_row = str(datetime.datetime(*xlrd.xldate_as_tuple(worksheet.cell_value(i, col - 1), workbook.datemode))) except: get_row = unicode(worksheet.cell_value(i, col - 1)) I have an exception in place for

Using xlrd to read Excel xls file containing Chinese and/or Hindi characters

[亡魂溺海] 提交于 2019-12-21 05:27:06
问题 http://scienceoss.com/read-excel-files-from-python/comment-page-1/#comment-1051 From the above link, I used this utility to read an XLS file. If the XLS file contains different language characters like Chinese or Hindi, it does not output them correctly. Is there a workaround for this? After Googling, I found this: import xlrd def upload_xls(dir,file,request): try: global msg global row_num row_num = [] header_arr = [] global file_path file_path = dir #reader = csv.reader(open(file),

Using xlrd to read Excel xls file containing Chinese and/or Hindi characters

元气小坏坏 提交于 2019-12-21 05:27:04
问题 http://scienceoss.com/read-excel-files-from-python/comment-page-1/#comment-1051 From the above link, I used this utility to read an XLS file. If the XLS file contains different language characters like Chinese or Hindi, it does not output them correctly. Is there a workaround for this? After Googling, I found this: import xlrd def upload_xls(dir,file,request): try: global msg global row_num row_num = [] header_arr = [] global file_path file_path = dir #reader = csv.reader(open(file),

How to check if valid excel file in python xlrd library

断了今生、忘了曾经 提交于 2019-12-21 04:50:10
问题 Is there any way with xlrd library to check if the file you use is a valid excel file? I know there's other libraries to check headers of files and I could use file extension check. But for the sake of multiplatformness I wonder if there's any function I could use in the xlrd library itself that could just return something like false when trying to open the file and then notify the user. I'm kind of new on Python so I tried getting something debugging the xlrd.open_workbook function with no

How to read data from Excel and write it to text file line by line?

流过昼夜 提交于 2019-12-21 02:44:45
问题 I want to write code to get data from Excel and write it to a text file. Here is the code I have: import xlrd import os.path wb = xlrd.open_workbook(os.path.join('D:\TRB 2014 Data','SPS1 demo data.xlsx')) wb.sheet_names() sh = wb.sheet_by_index(0) i = 1 while sh.cell(i,11).value != 0: Load = sh.cell(i,11).value D1 = sh.cell(i,13).value D2 = sh.cell(i,14).value D3 = sh.cell(i,15).value D4 = sh.cell(i,16).value D5 = sh.cell(i,17).value D6 = sh.cell(i,18).value D7 = sh.cell(i,19).value DB1 = str

how to use format read from xlrd and write thru xlsxwriter in python

五迷三道 提交于 2019-12-20 04:12:20
问题 I am reading an excel file using xlrd. Doing some macro replacing and then writing thru xlsxwriter. Without reading and copying formatting info the code works but when I add formatting info I get an error (at the bottom) The code snippet is below..I read a xls file, for each data row I replace token macros with the values and write back. when I try to close the output_workbook I get an error filePath = os.path.realpath(os.path.join(inputPath,filename)) input_workbook = open_workbook(filePath,

How to get line number in excel sheet using python?

三世轮回 提交于 2019-12-18 19:40:25
问题 I have an Excel sheet like this: A B C D E F G 1 0 0 0 2 0 0 3 0 4 5 0 0 0 0 0 0 0 6 0 0 0 And every '0' represents some data values, I am reading the values and comparing them with my original data, when the data match fails it returns a message. What I want is to return the line number of excel sheet as well as the column number or particularly the CELL location. Please help me doing this! 回答1: Try this: import xlrd workbook = xlrd.open_workbook('book.xls') for sheet in workbook.sheets():

Opening and reading an excel .xlsx file in python

↘锁芯ラ 提交于 2019-12-18 16:53:50
问题 I'm trying to open an excel .xlsx file with python but am unable to find a way to do it, I've tried using pandas but it's wanting to use a library called NumPy I've tried to install numpy but it still can't find numpy. I've also tried using the xlrd library but I get the following traceback: Traceback (most recent call last): File "C:\test.py", line 3, in <module> book = open_workbook('test.xlsx') File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 370, in open_workbook biff_version =

Python xlrd: suppress warning messages

蓝咒 提交于 2019-12-18 16:09:52
问题 I am using xlrd to process Excel files. I am running a script on a folder that contains many files, and I am printing messages related to the files. However, for each file I run, I get the following xlrd-generated error message as well: WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero Is there a way to suppress this error message, so the CLI will only print the message I want it to? 回答1: Check out the relevant part of the xlrd docs. The 2nd arg of the open_workbook