xlrd

pivots using pyExcelerator/xlrd

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:51:54
问题 How can I go about creating a worksheet (within an excel workbook) with a pivot table using python libs like pyExcelerator / xlrd? I need to generate a daily report that has a pivot table to summarize data on other sheets. One option would be to have a blank template that I copy and populate with the data. In this case, is there a way to refresh the pivot from code? Any other suggestions? 回答1: Please clarify (by editing your question) whether "sheet" is an abbreviation of "spreadsheet" and

Copying only worksheet of XLS to become new worksheet in new XLS using Python?

无人久伴 提交于 2019-12-11 00:31:14
问题 Using the Python test code below I am trying to copy the only worksheet in an Excel ( *.xls ) file into a new Excel file with one worksheet. The input spreadsheet looks like: from copy import deepcopy from xlrd import open_workbook from xlutils.copy import copy as copy from xlwt import Workbook rb = open_workbook(r"C:\Temp\test1.xls",formatting_info=True) wb = copy(rb) new_book = Workbook() r_sheet = rb.sheet_by_index(0) sheets = [] w_sheet = deepcopy(wb.get_sheet(0)) w_sheet.set_name("test1"

The col output in xlrd printing something with appears to be xf formatting text. How do I get rid of this?

血红的双手。 提交于 2019-12-10 23:59:29
问题 I am using XLRD to attempt to read from and manipulate string text encapsulated within the cells of my excel document. I am posting my code, as well as the text that is returned when I choose to print a certain column. import xlrd data = xlrd.open_workbook('data.xls') sheetname = data.sheet_names() employees = data.sheet_by_index(0) print employees.col(2) >>>[text:u'employee_first', text:u'\u201cRichard\u201d', text:u'\u201cCatesby\u201d', text:u'\u201cBrian\u201d'] My intention is to create

Python Excel date/time read in issue

 ̄綄美尐妖づ 提交于 2019-12-10 17:18:14
问题 I am trying to read dates/time off an excel sheet using Python, but I only want to read in the time so I can perform computations on it. For example if I have a date in the format: 3/11/2003 4:03:00 AM on my excel sheet how can I read in just the 4:03:00 in Python? I ultimately want to be able to subtract hours, mins, or seconds from the read in time. 回答1: The best option would be to convert the date to datetime using xldate_as_tuple. Assuming you have an test.xls file with 3/11/2003 4:03:00

Python xlrd parse Excel xlsx to csv with date conversion

坚强是说给别人听的谎言 提交于 2019-12-10 15:27:03
问题 I am trying to parse an Excel.xlsx file to a csv file. Here is the Excel file: Date Person 1 Person 2 02/03/2015 Bob James A 03/03/2015 Billy Nic 04/03/2015 Sally Mark 05/03/2015 Alan James A 06/03/2015 James W James A My Python script: import xlrd import csv book = xlrd.open_workbook('rota.xlsx') sheet = book.sheet_by_name('Sheet1') csvfile = open('output.csv', 'wb') wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL) for rownum in range(sheet.nrows): wr.writerow(sheet.row_values(rownum))

How to add new column and row to .xls file using xlrd

十年热恋 提交于 2019-12-10 11:29:19
问题 How do you add a new column and/or row to a sheet in xlrd? I have a .xls file that I read using open_workbook() and I need to add a new column("bouncebacks") to the first sheet then new rows to that sheet but I cannot find any functions in the xlrd documentation that shows how to add new rows and/or columns? If I cant add a row/column in xlrd is there another way/library that allows me to add a row or column to an .xls file? Can you show me how I can add a row and column to a sheet? import

python excel processing error

最后都变了- 提交于 2019-12-10 10:53:48
问题 I am working on the excel processing using python. I am using xlrd module (version 0.6.1) for the same. I am abe to fetch most of the excel files but for some excel files it gives me error as : XLRDError: Expected BOF record; found 0x213c Can anyone let me know about how to solve this issue? thanks in advance. 回答1: What you have is most probably an "XML Spreadsheet 2003 (*.xml)" file ... "<!" aka "\x3c\x21" (which is what XML streams start with) is being interpreted as the little-endian

Adding a sheet to an existing excel worksheet without deleting other sheet

≯℡__Kan透↙ 提交于 2019-12-10 10:19:06
问题 I am trying to add a sheet to the excel file: ex.xls and whenever I do it deletes all the previously made sheets. How do I add a sheet to this excel file without deleting the other sheets? Here is my code to create a sheet: import xlwt import xlrd wb = Workbook() Sheet1 = wb.add_sheet('Sheet1') wb.save('ex.xls') 回答1: I believe this is the only way to do what you want: import xlrd, xlwt from xlutils.copy import copy as xl_copy # open existing workbook rb = xlrd.open_workbook('ex.xls',

how to open xlsx file with python 3

末鹿安然 提交于 2019-12-09 17:56:14
问题 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 回答1: You can use Pandas pandas

How to set NULL for IntegerField instead of setting 0?

和自甴很熟 提交于 2019-12-09 14:16:35
问题 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 models, instead of NULL. This means that when my Person model doesn't have an age, that age gets recorded as 0, instead of as NULL. What's the best way to change this? I've tried doing this: age = models.IntegerField(blank=True, null=True) But the