xlrd

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

℡╲_俬逩灬. 提交于 2019-12-06 14:39:38
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,'TEMPLATE.xls'), on_demand=True, formatting_info=True) swb2 = xlrd.open_workbook(os.path.join(envconfig

python对Excel的读取

时间秒杀一切 提交于 2019-12-06 12:36:00
  在python自动化中,经常会遇到对数据文件的操作,比如添加多名员工,但是直接将员工数据写在python文件中,不但工作量大,要是以后再次遇到类似批量数据操作还会写在python文件中吗?   应对这一问题,可以将数据写excel文件,针对excel 文件进行操作,完美解决。   本文仅介绍python对excel的操作    安装xlrd 库   xlrd库 官方地址: https://pypi.org/project/xlrd/   pip install xlrd         笔者在安装时使用了 pip3 install xlrd   原因:笔者同时安装了python2 和 python3   如果pip的话会默认将库安装到python2中,python3中不能直接调用。   那么到底是使用pip 还是pip3进行安装呢?     如果系统中只安装了Python2,那么就只能使用pip。     如果系统中只安装了Python3,那么既可以使用pip也可以使用pip3,二者是等价的。     如果系统中同时安装了Python2和Python3,则pip默认给Python2用,pip3指定给Python3用。 Xlrd 库简单的使用   以如下excel文件为例进行操作   文件名为demo,有两个sheet,名为工作表1和工作表2   工作表1中有如下数据      

python excel processing error

亡梦爱人 提交于 2019-12-06 09:57:25
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. 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 number 0x213c . Notepad: First two lines: <?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> You can

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

徘徊边缘 提交于 2019-12-06 03:39:34
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') 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', formatting_info=True) # make a copy of it wb = xl_copy(rb) # add sheet to workbook with existing sheets Sheet1 = wb

♦ python解决open()函数、xlrd.open_workbook()函数文件名包含中文,sheet名包含中文报错的问题

浪子不回头ぞ 提交于 2019-12-06 02:44:51
那我就一下面积个问题对xlrd模块进行学习一下: 1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模块?   ♦python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库。 今天就先来说一下xlrd模块: 一、安装xlrd模块   ♦ 到python官网下载 http://pypi.python.org/pypi/xlrd 模块安装,前提是已经安装了python 环境。   ♦或者在cmd窗口 pip install xlrd 二、使用介绍 1、常用单元格中的数据类型   ♦ 0. empty(空的),1 string(text), 2 number, 3 date, 4 boolean, 5 error, 6 blank(空白表格) 2、导入模块 import xlrd 3、打开Excel文件读取数据 data = xlrd.open_workbook(filename)#文件名以及路径,如果路径或者文件名有中文给前面加一个r拜师原生字符。  4、常用的函数 ♦ excel中最重要的方法就是book和sheet的操作 1)获取book中一个工作表 table = data.sheets()[0] #通过索引顺序获取 table = data.sheet_by_index

Accessing worksheets using xlwt 'get_sheet' method

六月ゝ 毕业季﹏ 提交于 2019-12-06 02:35:50
I would like to access worksheets of a spreadsheet. I've copied the main workbook to another workbook using xlutils.copy(). But don't know the right way to access worksheets using xlwt module. My sample code: import xlrd import xlwt from xlutils.copy import copy wb1 = xlrd.open_workbook('workbook1.xls', formatting_info=True) wb2 = copy(master_wb) worksheet_name = 'XYZ' (worksheet_name is a iterative parameter) worksheet = wb2.get_sheet(worksheet_name) Could someone please tell me what's the right command line to access the existing worksheets in a workbook using xlwt module? I know we can use

I'm having a lot of trouble installing xlrd 0.9.2 for python

别等时光非礼了梦想. 提交于 2019-12-05 22:13:50
问题 Can someone give me a guide for morons? I am somewhat out of my depth here. So far I have downloaded xlrd 0.9.2 and tried to follow the readme, but neither I nor ctrl-f can find the installer mentioned. 回答1: download The current version of xlrd can be found here: https://pypi.python.org/pypi/xlrd extract the folder somewhere go to the folder you extracted to ... find setup.py open command window (start -> run-> cmd) cd into the directory with setup.py type: python setup.py install you may

28.python操作excel表格(xlrd/xlwt)

岁酱吖の 提交于 2019-12-05 19:32:14
python读excel——xlrd 这个过程有几个比较麻烦的问题,比如读取日期、读合并单元格内容。下面先看看基本的操作: 首先读一个excel文件,有两个sheet,测试用第二个sheet,sheet2内容如下: python 对 excel基本的操作如下: # -*- coding: utf-8 -*- import xlrdimport xlwt from datetime import date,datetime def read_excel(): # 打开文件 workbook = xlrd.open_workbook(r'F:\demo.xlsx') # 获取所有sheet print workbook.sheet_names() # [u'sheet1', u'sheet2'] sheet2_name = workbook.sheet_names()[1] # 根据sheet索引或者名称获取sheet内容 sheet2 = workbook.sheet_by_index(1) # sheet索引从0开始 sheet2 = workbook.sheet_by_name('sheet2') # sheet的名称,行数,列数 print sheet2.name,sheet2.nrows,sheet2.ncols # 获取整行和整列的值(数组) rows = sheet2

Python中xlrd和xlwt模块使用方法----》》数据库数据导出(之一)

℡╲_俬逩灬. 提交于 2019-12-05 15:45:23
xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入。 (1) 打开excel文件并获取所有sheet >>> import xlrd >>> workbook = xlrd.open_workbook(r'D:\Program Files\Notepad++\Student.xlsx') >>> print workbook.sheet_names() [u'Sheet1', u'Sheet2', u'Sheet3'] (2) 根据下标获取sheet名称 >>> sheet2_name=workbook.sheet_names()[1] >>> print sheet2_name Sheet2 (3) 根据sheet索引或者名称获取sheet内容,同时获取sheet名称、行数、列数。 >>> sheet2 = workbook.sheet_by_index(1) >>> print sheet2.name,sheet2.nrows,sheet2.ncols Sheet2 6 5 >>> sheet2 = workbook.sheet_by_name('Sheet2') >>> print sheet2.name,sheet2.nrows,sheet2.ncols Sheet2 6 5 (4) 根据sheet名称获取整行和整列的值 >>> sheet2

Read workbook properties using python and xlrd

左心房为你撑大大i 提交于 2019-12-05 13:59:44
Is there a way to read the excel file properties using xlrd? I refer not to cell presentation properties, but general workbook properties. Thanks a lot in advance. Apart from the username (last person to save the worksheet) the Book instance as returned by open_workbook does not seem to have any properties. I recursively dumped the Book ( dumping its dict if a xlrd.BaseObject) and could not find anything in that way. The test files for sure had an author, company and some custom metadata. FWIW: LibreOffice does not seem to be able to find author and company either (or does not display them),