xlrd

python excel

别来无恙 提交于 2019-12-08 20:13:02
利用Python读取和修改Excel文件(包括xls文件和xlsx文件)——基于xlrd、xlwt和openpyxl模块 2018-08-19 16:28:31 TheGkeone 阅读数 38477 收藏 更多 分类专栏: Python 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/sinat_28576553/article/details/81275650 本文介绍一下使用Python对Excel文件的基本操作,包括使用xlrd模块读取excel文件,使用xlwt模块将数据写入excel文件,使用openpyxl模块读取写入和修改excel文件。 目录 1、使用xlrd模块对xls文件进行读操作 1.1 获取工作簿对象 1.2 获取工作表对象 1.3 获取工作表的基本信息 1.4 按行或列方式获得工作表的数据 1.5 获取某一个单元格的数据 2、使用xlwt模块对xls文件进行写操作 2.1 创建工作簿 2.2 创建工作表 2.3 按单元格的方式向工作表中添加数据 2.4 按行或列方式向工作表中添加数据 2.5 保存创建的文件 3、使用openpyxl模块对xlsx文件进行读操作 3.1 获取工作簿对象 3.2 获取所有工作表名 3.3 获取工作表对象 3.4

Is it possible to insert a worksheet into an existing workbook using Python?

假如想象 提交于 2019-12-08 07:04:33
问题 The Problem Creation of fancy reports using Pandas and Python. Proposed Solution Using a template xlsx file containing a template sheet nicely formatted with references to another pre-populated worksheet, delete the pre-populated sheet and insert the new worksheet from pandas. The template sheet will lose the links reverting to #REF so these will need to be renamed. I tried: import os import xlrd, xlwt import envconfig swb1 = xlrd.open_workbook(os.path.join(envconfig.REPORT_WRITER_PATH,

Pandas.read_excel: Unsupported format, or corrupt file: Expected BOF record

孤街醉人 提交于 2019-12-08 04:55:06
问题 I'm trying to use pandas.read_excel to read in .xls files. It succeeds on most of my .xls files, but then for some it errors out with the following error message: Unsupported format, or corrupt file: Expected BOF record; found '\x00\x05\x16\x07\x00\x02\x00\x00' I've been trying to research why this is happening to some, but not all files. The xlrd version is 1.0.0. I tried to manually read in with xlrd.open_workbook and I get the same result. Does anyone know what file type, this BOF record

Pandas.read_excel: Unsupported format, or corrupt file: Expected BOF record

£可爱£侵袭症+ 提交于 2019-12-08 04:28:27
I'm trying to use pandas.read_excel to read in .xls files. It succeeds on most of my .xls files, but then for some it errors out with the following error message: Unsupported format, or corrupt file: Expected BOF record; found '\x00\x05\x16\x07\x00\x02\x00\x00' I've been trying to research why this is happening to some, but not all files. The xlrd version is 1.0.0. I tried to manually read in with xlrd.open_workbook and I get the same result. Does anyone know what file type, this BOF record is referring to? There are various reasons to why that error message appeared. However, the main reason

Using xlrd to get list of excel values in python

▼魔方 西西 提交于 2019-12-08 03:26:15
问题 I am trying to read a list of values in a column in an excel sheet. However, the length of the column varies every time, so I don't know the length of the list. How do I get python to read all the values in a column and stop when the cells are empty using xlrd? 回答1: for i in range(worksheet.nrows): will iterate through all the rows in the worksheet if you were interested in column 0 for example c0 = [worksheet.row_values(i)[0] for i in range(worksheet.nrows) if worksheet.row_values(i)[0]] or

Changing formats of contents in columns in an existing Excel workbook

隐身守侯 提交于 2019-12-07 20:45:09
问题 I want to change the format of the contents in an Excel workbook. Environment: Win 7; Python 2.76 I want to change the columns A, B and C to the desired format. What I have is: from openpyxl import Workbook from openpyxl import load_workbook wb = load_workbook('c:\\oldfile.xls') ws = wb.active d = ws.cell(column = 0) # or 1, 2, 3 d.style = Style(font=Font(bold=False), borders=Borders(left=Border(border_style='none'), right=Border(border_style='none'), top=Border(border_style='none'), bottom

Python Excel template read and re-write, maintaining formulae and formatting

末鹿安然 提交于 2019-12-07 04:29:28
问题 I've run the gamut and can't seem to find what I'm looking for. All threads I found here end up in dead ends for me. xlrd, xlwt, and xlutils almost do what I need, but… The basic idea is that I need to use Python to write simple data (strings) to a particular sheet of an Excel template and write out that template to a new .xls file. Reading in the template, copying it to a new workbook object, writing in the new values, and writing out the new .xls file is no problem. However, I cannot find a

Get column data by Column name and sheet name

限于喜欢 提交于 2019-12-07 00:57:25
问题 Is there a way to access all rows in a column in a specific sheet by using python xlrd. e.g: workbook = xlrd.open_workbook('ESC data.xlsx', on_demand=True) sheet = workbook.sheet['sheetname'] arrayofvalues = sheet['columnname'] Or do i have to create a dictionary by myself? The excel is pretty big so i would love to avoid iterating over all the colnames/sheets 回答1: Yes, you are looking for the col_values() worksheet method. Instead of arrayofvalues = sheet['columnname'] you need to do

Using xlrd to get list of excel values in python

孤者浪人 提交于 2019-12-06 21:14:06
I am trying to read a list of values in a column in an excel sheet. However, the length of the column varies every time, so I don't know the length of the list. How do I get python to read all the values in a column and stop when the cells are empty using xlrd? for i in range(worksheet.nrows): will iterate through all the rows in the worksheet if you were interested in column 0 for example c0 = [worksheet.row_values(i)[0] for i in range(worksheet.nrows) if worksheet.row_values(i)[0]] or even better make this a generator column_generator = (worksheet.row_values(i)[0] for i in range(worksheet

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

不想你离开。 提交于 2019-12-06 14:52:52
问题 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. 回答1: 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